[SOLVED] Alternative to system()
-
Hi !
I am looking for an alternative to system(), in order to execute a command line that looks like this :
@ system("myexecutable -ip <ip address> -pw <password> -othercommand > text.txt"); @I tried to use QProcess for this, but I can't make it work.
Does someone have an idea of something I could use instead, or maybe the correct syntax when using QProcess::execute ?Thank you !
-
On Windows, you need to use QProcess to launch cmd.exe, and then provide your command line through the /C parameter, like this:
@
QProcess::startDetached("cmd.exe /C myexecutable -ip <ip address> -pw <password> -othercommand > text.txt");
@You need to experiment with using QStringList to pass arguments, it usually takes several tries to make it work.
On Linux and Mac, the line you posted is correct and should work.
-
Oh sorry, I have missed the redirection. You need to use "QProcess::setStandardOutputFile":http://qt-project.org/doc/qt-5/qprocess.html#setStandardOutputFile (or process).