How to run a C++ Program interactive using external tools in gedit - c++

I'm trying to run my C++ program interactively straight in gedit using external tools.
I've already written a Python tool for compiling it, but when using os.system("./program.out") all input for the program is set to 0 (but it is getting executed right, though).
Since using Python for executing it interactive would be rather difficult, im looking for another solution.
#!/usr/bin/env python3
import os
filename = os.getenv("GEDIT_CURRENT_DOCUMENT_NAME")
fout = "%s%s"%(filename[:len(filename)-4], ".out") #
os.system("c++ -o %s %s" % (fout,filename))
os.system("./%s" % fout)
the compiling works flawless, but ./program.out also doesn't give the wanted result using bash.
Any suggestions?

I guess i've found an answer. It may not be the most beautiful solution, but it works.
When defining a tool you can choose the input in a drop-down menu, there is an option for selected text as input.
So for example, if you have a program that reads 3 variables from stdin, you can add a comment to your code like //1 3 2, only select the numbers and then run your tool.
These numbers will be used as input in this order, somehow it only works with spaces.
A cruel way of implementing this would be to scan for input calls in the source code and ask for them via zenity in the gedit tool, i guess.

And here is another solution:
I can just use echo 3 2 1 | ./program.out in the tool
this makes everything way more easy

Related

Running Python programs in python.exe, the command prompt, and IDLE

Let me preface this post that I am incredibly new to python. I took a course in codeacademy but haven't actually used python on my own computer until now. Let me also explain to everyone that my coding experience is limited to VBA and excel. I have very little knowledge of how to use the command prompt, how libraries work, etc, etc.
I'm having some issues. I've changed my directory to recognize python when I type python in my command prompt. Then I can do simple things like
print "hello"
however if i write something like this
def firstfunction(t):
print t+5
return
firstfunction(5)
I would expect this to print the number 10, however I get the following error:
File"stdin", line 4
first function(5)
^
syntaxerror: invalid syntax
However if I use this in IDLE and run it it works fine.
Next I've saved some python programs I wrote. One I saved as Hello.py
i want to run this code from my python exe or from the command prompt but can't figure out how.
Please any answers helpful, if you use computer lingo, try and keep it as simple as possible. I'm super new!
Thanks
If the location of python is not included in your path, add it. But in any case, you should be able to run this successfully from the directory containing your python.exe.
e.g, if python lives in C:\Python27:
cd C:\Python27
python mypythonscript.py

Enthought Canopy User Input

I'm using Enthought Canopy on Mac OSX Lion. I'm using this because of the ease at which modules and libraries can be downloaded and installed (had a lot of trouble downloading pandas and numpy through terminal due to a number of issues).
So, now I'm doing my coding for a project in Canopy, which is OK (still prefer Wing, though). The problem I have encountered is that I need to ask the user for input. When I do, for instance:
x = input('Enter your input here: ')
I get an EOF error as follows: EOFError: EOF when reading a line
I was looking around and believe that this may be something which Canopy does not support. Was wondering if this is, indeed, the case and if there is a solution/workaround to this problem?
I assume that you are entering this code in the IPython shell that is embedded in the Canopy editor. This is an upstream bug/deficiency in IPython's Qt console. Because the remote shell is not actually hooked up to a terminal, functions like input() and raw_input() need to be replaced to get the input from the GUI console widget instead. IPython (and thus Canopy) does replace raw_input() but does not replace input(). This code will work using Canopy's Python interpreter if you were to put it into a script and execute it from the command line, and it would also work in a terminal instance of IPython. It was most likely overlooked because it is usually considered a bad idea to use input().
Please use raw_input() instead and parse the string that you get. You can use eval() if you must, but I do recommend using a more specific parsing/conversion function.

Reading output from the command line

I'm trying to write a simple GUI for Wget. I'm looking for advice on how to read information from the command line output that Wget generates when it is doing a run. I'd like to update that download information real time to a list box or some equivalent. The GUI will be in Visual Basic. I know programs like WinWget do this, and their source code is available, but I don't know the language that's written in well enough to find what I'm looking for.
tl;dr: I need to update a list box real time with command line output.
There are two ways to use the output of one console application for the input of an other:
The first way is to use the | operator; for example:
dir |more
The second way is to write the data into a file and process it later.
dir > data.txt

Simple interactive prompt in C++

I work on an application that usually runs unattended. Now I need to add to it something like an interactive prompt. In the interactive mode the operator will be able to give simple commands to the application - nothing fancy, simple commands like start and stop. Parametrized commands (e.g. repeat 10) and commands history could be nice too.
Do you know, by chance, any library that helps with such tasks. I've been thinking about something that works like boost::program_options or gflags but for an interactive prompt and not for command line parameters. Any ideas?
Thanks
Readline is one the best known libraries for this
http://tiswww.case.edu/php/chet/readline/rltop.html
It is covered by GPL, so it is only possible to use in GPL-compatible programs.
I did a quick search for alternatives, and found this:
http://github.com/antirez/linenoise
I'm not sure if the following is a reasonable amount of work for what you're trying to do, but Python has a very nice Command Line Interface (CLI) building library called cmd2. If it's possible to expose the relevant parts of your apps to Python using SWIG or CTypes, then doing the rest should be easy.
Here's a nice video presentation about cmd2:
PyCon 2010:Easy command-line applications with cmd and cmd2
HTH
One possibilty is to open a TCP port and accept messages in text format. Then you can telnet to that port and issue simple commands.

Program Interaction and testing via bash script

I've just completed the coding section of simple homework assignment for my C++ class. The second part of the assignment requires us to verify our code's input validation. (The program takes several different values as inputs from a user and prints those values to a file)
I was hoping that I could use bash script for this. Is there any way to use bash script to run and interact with a program? How can I put the program's output into a variable (note that program has a series of input requests and outputs).
Thanks
To build on #Travis' answer, create two files: one holds your inputs (input.txt) and one holds the expected output (expected_output.txt). Then do the following:
./myprogram <input.txt >output.txt
diff output.txt expected_output.txt
If the diff command has any output, there's a problem.
You can do much of this with a shell script but you might want to consider using some other testing tools instead like CppUnit or expect.