PDA

View Full Version : Issue with QProcess and redirectiion operator as arguments



nikhilqt
25th February 2009, 11:01
Hi,

I am using QProcess for executing an executable and the syntax goes like this,

QString cmd = " some.exe"
QStringList args;

args << " < " << "./input.txt" << " > " << "./output.txt"

QProcess* proc = new QProcess( this );

proc.start( cmd , args );
proc.waitForStarted();

As per the above code the exe has to run taking " args " as argument list. since i have provided the input to "some.exe" using redirection operator it should not ask user the input, but it is not happening as expected.

but if i provide the same commands in .bat file and if i give that bat file as input for QProcess it works as expected.

Can anyone throw light on this , why exactly it is not able to run ?

Thanks in advance,
Nikhil

talk2amulya
25th February 2009, 12:33
provide args in one string:

args << " < input.txt > output.txt"

hopefully it'll work

caduel
25th February 2009, 13:41
">" is not an argument to your program, but to the shell executing your program.
if you call "sh" and pass the rest (including your app) as args, it might work.

On the other hand, maybe (only maybe) you don't need to redirect the output:
* if you want to ignore it: just close the channel on the QProcess
* if you want to read it with Qt: no need to write it to a file first, just read from QProcess

nikhilqt
25th February 2009, 16:55
Thanks a lot for the reply. I will try them.