QProcess start with files from stdin and stdout

qprocess, qt, stdin, stdout

Solution

Reading from and writing into files using `<` respectively `>` is a syntax feature of the shell. If you run the command line `programm < file1 > file2` using a shell like `sh`, the command `program` gets executed only, with no arguments at all. Assigning the programs channels for input and output to the given files doesn't have anything to do with the command itself.

But `QProcess` can be told to simulate this behaviour by using these methods:

`QProcess::setStandardInputFile(QString fileName)` `QProcess::setStandardOutputFile(QString fileName)`

So your code becomes:

QProcess *proc = new QProcess;
proc->setReadChannelMode(QProcess::SeparateChannels);
proc->setStandardInputFile("file1");
proc->setStandardOutputFile("file2");
proc->start("program");

Problem

I need to run following statement from QProcess: ``` programm < file1 > file2 ``` in QT: ``` QProcess *proc = new QProcess; proc->setReadChannelMode(QProcess::SeparateChannels); proc->start("program < \"file1\" > \"file2\"", QIODevice::ReadWrite); ``` But somehow it does not work. I see in taskmanager, that the command looks correctly, but it seems as the program is executed without any arguments. Where is my error?

Original source