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?
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With