Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QProcess start, correct way to pass arguments with > piping to an output file.



  • Trying to pipe output of an executable to a file. Code is:

    	QString p = QString::fromStdString(param);
    	QStringList arguments;
    	arguments << p;
    
    	proc->start(path, arguments);
    

    The values of the vars at run time are:

    +		p	-listxml > mame.dat	QString
    +		param	"-listxml > mame.dat"	std::string
    +		path	C:\mame\mame64.exe	QString
    

    Now the weird thing.... The debug output:

    >> Started ok
    "Error: unknown option: -listxml > mame.dat\r\n"
    >>>>> Exit Code: QProcess::NormalExit
    Program ran successfully
    

    Where did the "\r\n" come from ? And how do I actually pass a arg to an exe to tell it to pipe in QProcess? And yes, that command via dos works fine. Can 't use a batch file before you ask because this programme will be put up on github and free to use, including source, so that means the end user won't have a batch file there. Hmmm


  • Qt Champions 2019

    Piping is a bash feature. So either start a bash shell or read the data from stdout and write it to your second process.



  • @jonndoe47
    As @Christian-Ehrlicher says, except that I doubt you'll have bash as you have a .exe so are probably under Windows :) It always helps to state OS when asking QProcess questions....

    The shortest, dirtiest answer is you need to go

    process->start("cmd", QStringList() << "/c" << "C:\\mame\\mame64.exe -listxml > mame.dat")
    

    Nicer here would be to use QProcess::setStandardOutputFile on mame.dat which you have previously opened for output as a QFile yourself in caller. Then you can go back to running "C:\\mame\\mame64.exe" as the executable (and pass -listxml argument). But that's more lines of code (only a couple, you can do that can't you?).



  • Done it all, i forgot > is part of command shell not program.... Doh! All ok now thank you all.


Log in to reply