PDA

View Full Version : Pipe multiple QProcess



akiross
29th April 2013, 11:42
Hello,
I would like to pipe together multiple processes, so that one or more produces the data and the others read.

I tried using QByteArray, as a buffer, but it's a bit tricky, because of the order in which processes starts and close. So I thought to use another QIODevice, like QBuffer, but I cannot find anything to feed a QIODevice as process stdin/out - but only setStandard(Input|Output|Error)File, which works with QStrings for actual paths.

I am seeking for a simple mechanism, where a the output processes are given one output file as a buffer, and this file is passed as input to the others.

What do you think is the best way to proceed?
Thanks!

EDIT:
Also, consider I need to push some generated data to the input processes before they actually start.

The tricky point is how to tell listening processes that input is finished, and therefore the input channel of receiving processes has to be closed correctly when ALL the producing processes (and my data source) have finished. I was thinking to something like a EOF sequence, but I do not think Qt works like that.

amleto
30th April 2013, 00:28
https://github.com/KholdStare/plumbingplusplus

or wait for c++ pipelines
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3534.html

akiross
30th April 2013, 00:38
:O that's very, very interesting! Thanks a lot :)

wysota
30th April 2013, 08:36
It's also very easy to implement a pipe based on QIODevice.

akiross
30th April 2013, 11:43
wysota, that's interesting. Reading briefly the QIODevice documentation it seems to me that such a pipe would be implemented sub-classing it, using a QByteArray to store writes and emitting readyReads, right?

The only thing I do not understand is if it's possible to automatically attach a QProcess to multiple QIODevice, so that when one has data ready, they are copied to every other connected device... In other words, I do not see why it should be more convenient to use a QIODevice to pipe.

wysota
30th April 2013, 14:19
wysota, that's interesting. Reading briefly the QIODevice documentation it seems to me that such a pipe would be implemented sub-classing it, using a QByteArray to store writes and emitting readyReads, right?
Basically, yes.


The only thing I do not understand is if it's possible to automatically attach a QProcess to multiple QIODevice
You can implement a multiplexer device that reads from one source and writes to multiple destinations.


In other words, I do not see why it should be more convenient to use a QIODevice to pipe.
It would be more convenient because you retain the QIODevice API so you can use the pipe with anything that can read from QIODevice or write to QIODevice. Bear in mind QProcess, QFile, QAbstractSocket are all QIODevice subclasses.

akiross
30th April 2013, 15:35
Well, my original post was mainly directed to the creation of the multiplexer itself, but it seems that I have to tailor a solution by myself.

Thanks anyway, I will consider creating a QIODevice to pipe (and multiplex).