PDA

View Full Version : Passing ">" to Qprocess command line



aguayro
23rd July 2015, 13:07
I'm trying to pass an argument to an exe file with QProcess in Windows:

procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml" <<">" << "mamelist.xml");
or
procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml>" <<" "mamelist.xml");
or
procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml" << ">mamelist.xml");
or
procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml>mamelist.xml");
or
procMame->start( tinfo.absoluteFilePath(), QStringList() << "-listxml > mamelist.xml");

Nothing works, but it does work manuall via CMD console...
With QProcess the command is never recognized (Command not found or takes ">" as a game name not as a output character for saving the xml file).
What i'm doing wrong?

yeye_olive
23rd July 2015, 13:53
When you type the command

foo.exe arg > bar
in the terminal, then the command interpreter (CMD) does NOT run foo.exe with the argument list {"arg", ">", "bar"}, because ">" is a part of the special syntax interpreted by CMD. Instead, CMD runs foo.exe with the single argument "arg" and writes its output to the file bar.

Therefore, you can either:

(Recommended) Do like CMD: with a QProcess, run foo.exe with the single argument "arg", and use QProcess::setStandardOutputFile() to redirect the output to a file.
Run CMD itself, so that it interprets the command: with a QProcess, run cmd.exe with the appropriate argument list, starting with "/c", and following with an escaped version of the command (which is tricky to get right). This is roughly equivalent to calling the system() function from the standard C library.

aguayro
23rd July 2015, 14:35
Thanks!! The Option 1 (redirect output to a file) is perfect.
Sometimes the answer is out there.. :D
Thanks again