How to communicate 3 QProcess?
-
What exactly do you mean?
- Is process #1 your "main" (Qt-based) application, which then spawns processes #2 and #3?
- Or is process #1 what is spawned by your "main" (Qt-based) application and process #1 will then spawn processes #2 and #3 without direct control of you "main" application?
First case should be handled well by QProcess, just use two separate QProcess objects for each child process you spawn. In the latter case, you can only interact (directly) with process #1 via QProcess, but not with #2 or #3.
-
Just use two QProcess objects, one for each process to start.
QProcess is inherited from QIODevice, so you can write to the process' STDIN via QProcess::write() and you can read from the process STDOUT/STDERR via QProcess::read(). See also QProcess::setReadChannel() to select between STDOUT, STDERR or both combined. Finally, you can use the signals readyReadStandardError and readyReadStandardOutput to read from the child process in an asynchronous way...
Inside your child processes, if they are not made with Qt, simply use printf() for writing to the STDOUT and use fread(..., stdin) to read from the STDIN...
See also:
http://doc-snapshot.qt-project.org/4.8/qprocess.html