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

Spitz
  • 31
  • 2

3 Answers3

2

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

James
  • 24,676
  • 13
  • 84
  • 130
2

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
  • 26,737
  • 4
  • 62
  • 93
0

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

almathie
  • 731
  • 5
  • 22