views:

132

answers:

3

I try to explain the situation:

  • I have a QT application written in C++ and QT.

  • This QT application starts a separate console C++ application that runs in the background.

  • These two communicate using perhaps sockets, don't know yet.

  • Console C++ application needs to start and stop my gnuradio python script. Also it needs to send parameters to it.

  • Once started, this gnuradio script runs independedly in infinite loop sending information to either the console or the QT application using sockets perhaps.

  • My console application needs to stop this gnuradio script from running when the order is given by the QT application.

The question is how can I stop this separate python script from my C++ console application ? Also is there anything I could do to make this more simple ?

Regards,

Spitz

+2  A: 

Sockets, or you could use DBUS python, and DBUS c++, if you want to be all free-desktopy :D

Autopulated
+2  A: 

Spawn python script as a new process using fork() and execv(). execv() (or any other function of the exec family) lets you pass arguments to the Python script. Use the child process ID to send a kill signal when you are done with the Python script.

Vijay Mathew
A: 

For your C++ program, you may wanna take a look here :

http://www.codeproject.com/KB/cpp/kill_process.aspx

Its gives you the basic code for creating and killing an external process. Remember that launching a python script means calling the python bin and giving the script as first argument.

The communication between your C++ app and the python script can be made via a named pipe

http://en.wikipedia.org/wiki/Named_pipe

but DBUS can work too.

My advice is :

1) start your C++ app from your QT app using QT's goodness. You can have these two communicate via standard I/O redirection (depending or what you really wanan do)

2) start your python script from your C++ following the example given above. And those two communicate via DBUS/Socket/Pipes.

Should do the trick

Snowangelic