pass data from a python application to a running c++ application [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I coded to applications one in python the other one in c++. In the middle of the python app I need to run the c++ app pass some input to it and receive the output. I already know that I can call the c++ app from python using subprocess but since that c++ app has to do some initial calculations each time it is called it makes my program really slow. So what I was looking for is this:
put my c++ app in an infinite while loop and keep it running. Then in my python app whenever I need a call to the c++ app just pass the data and get the output. This way i can avoid repeating the initial state every time I need to make this call.
Is there anyway to do this? Like writing another application that controls all of these. Also there can be multiple instances of the python app running but I want to have just one of the c++ app running since it takes a lot of memory

Using subprocess.Popen you can open a process and keep it open, use the stdin and stdout to communicate with it. When you open the process use: stdout=subprocess.PIPE, stdin=subprocess.PIPE .
You can then write to process.stdin and read from process.stdout the output of the c++ program.

You can do it with boost python. Design a class that perform the initial computation in its constructor and a method to perform the computation. You wrap it and instantiate it from python once.
subprocess solution is possible too, as asafpr answered.
You also can set a XML-RPC server in the C++ app and call it from Python with with xmlrpclib module.

Related

Is there a way to have a C or C++ program open a new terminal window and start executing code for you? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
I want to create a C or C++ program that automates some things for me.
The idea is as such: I run the program ./a.out and sit back and watch as it opens up three or four new terminal windows and runs various UNIX commands. Is there a way to do this?
I am on a MacBook.
As the comments point out, this is probably best accomplished by a shell script. However, you can execute shell commands from C with the system(3) standard library function. To open a terminal, just run a terminal with a particular command. For example:
system("xterm -e 'echo hello; sleep 5'");

How to run gcc compiler from my qt application? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
1- I am working on a project and i have made a simple GUI but i want to make a run button in my GUI to compile and run c code ??
(i want to make simple ide so i used qt to make my ui but i can not make a button which send arg to windows terminal )
2- How to have a good start with Qt (need a good tutorial)
You can run any program from Qt5 and capture it's standard output using the QProcess class. The official documentation with examples is here: http://doc.qt.io/qt-5/qprocess.html
So what I would do then is simply make a GUI with 2 QTextEdit widgets, one for the code and one for the compile/run output. Documentation for QTextEdit is here: http://doc.qt.io/qt-5/qtextedit.html
So the "compile and run" button would simply
Take content of upper QTextEdit into a temporary text file on disk. Documentation for QFile is here: http://doc.qt.io/qt-5/qfile.html
Start gcc to complie the file using QProcess and capture the output in a string
Replace the content of the bottom QTextEdit with the output of the compilation.
Look at return code from QProcess to see if compilation was successful.
For successful build, simply invoke QProcess again, this time for the executable that was built by gcc to run the code, while appending any output to the bottom QTextEdit.
NOTE: As an exercise this is probably going to be fun and provide ample opportunity for learning, however I doubt this would be very useful on its own.
Good luck!

How to prevent a windows application from being killed/terminate or stop [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a windows c++ application which runs under the normal (non-admin) user. I want that no user should be able to close/stop/terminate this application by any means.
Is there any active directory group policy available to achieve this or I need to do some programming for the same
The only way I know is that your app will launch run 2 or more background processes that check every few ms that your app and the other backgrounds are running, if not it re-launches them.This makes it very had or impossible to terminate your app manually.
You application might need to save its state to disk , if it needs to re-launch to the same stat is was when destroyed
you can also disable the close button or whatever can terminate your application. Also disable the taskmanager so users cannot kill your application
There is a technique called hooking which will allow injection of your code into Windows DLL's, altering certain behaviours performed by the operating system.
This would prevent the operating system killing these proccesses using the core DLL's.
There is a downside to this method though as it may flag up as a virus on anti-rootkit systems as this is a technique often used to prevent the user from killing an infection.

Install a program from another program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm a game developer and my current task is to create a game launcher. If you know what is Battle.net, you'll understand what I mean. For the launcher itself we're using the InstallBuilder from Bitrock. But the end user should have a possibility to install actual game pressing a button in the launcher. The launcher then will download files, register them, show progress bar, allow to play a game before full download, create a shortcut etc. - the same way as Battle.net launcher behave.
So, my question - where to start? I suppose that this is platform specific, so for now I'm interested in Windows. I'm using VS2013, Qt.
First of all, you must create an installer which will handle the actual installation of the application. You can then call the installer from your other process (in your case the launcher.)
In Qt you can use the QProcess Class which is documented here. I think that the documentation is really good and will answer most of your questions but what you need to do more or less is this:
QObject *parent;
...
QString program = "./path/to/your/installer";
QStringList arguments;
arguments << "-option" << "argument";
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);
(Copied pretty much verbatim for the documentation.)
You also have the option of interacting with your installer after its execution start (you can for example read the exit code) so that you can monitor the installation progress form your launcher.

Issue while entering response on console [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am connecting to machine using Telnet function, pushing some file to it using Putty and till date it worked fine. But now all of sudden, it has started throwing me an error while I am trying to push some file to the machine using subprocess.Popen().
The error is :
Result: WARNING - POTENTIAL SECURITY BREACH!
The server's host key does not match the one PuTTY has
cached in the registry. This means that either the
server administrator has changed the host key, or you
have actually connected to another computer pretending
to be the server.
Update cached key? (y/n, Return cancels connection) Connection abandoned.
Lost connection
I want to add one step in my scrip that, if console has something like this, then it enter "Yes/y" on console.
I have tried this thing to make it over :
if 'Result: WARNING - POTENTIAL SECURITY BREACH!' in sys.argv:
raw_input("y\n")
time.sleep(1)
But it is not working.. Any help on this!!!
For the first part of your question, you should look in the Registry key HKEY_CURRENT_USER\SoftWare\SimonTatham\PuTTY\SshHostKeys to remove the host computer whose host key has changed (see https://superuser.com/questions/197489/where-does-putty-store-known-hosts-information-on-windows).
For the second part, raw_input() is used to get input from the user, not for submitting values to a subprocess. I'm not sure, but I think that PuTTY's pscp would be getting it's y/n value from stdin, so you could either use subprocess's Popen() to always pass in a "y" just in case (see Python - How do I pass a string into subprocess.Popen (using the stdin argument)?) or you can try passing pscp the "-batch" argument, which sounds like it shouldn't prevent the prompt (see http://the.earth.li/~sgtatham/putty/0.62/htmldoc/Chapter5.html#pscp-usage).