[SOLVED] QProcess starting but not showing
-
Hello!
Hopefully I'm not missing something simple here but when I attempt to use QProcess with cmd.exe, it starts the process but does not display. Some code:
@QProcess *process = new QProcess();
process->setProgram("cmd");
process->start();
if(process->state() != QProcess::NotRunning)
process->waitForFinished(-1);@This seems to work correctly when using process->startDetached(); I'm using Qt 5.2 on Windows 7. Any help would be great, thanks!
-
What do you expect to see?
cmd.exe does not spawn any windows and without external help it will not display anything.
You can read an output of cmd.exe using "readAllStandardOutput":http://qt-project.org/doc/qt-5/qprocess.html#readAllStandardOutput or other read functions and then display it in your window or put it to logfile. -
As far as I know, cmd.exe spawns a black DOS command line window for user interaction. What do you mean by "external help" for it to display?
Just adding to the information, cmd.exe runs in background without doing anything and without showing the command line window.
Thanks for the reply!
-
You don't see new DOS window when you try to run cmd.exe as child of your process because your program already has a MainWindow and Windows does not create new MainWindow. But when you spawn cmd.exe as detached process without parent then Windows provides new MainWindow.
If you would like to see the output or enter some input of the application inside your program you need to read stdout, stderr and write to stdin of the application.
cmd.exe does not do anything by itself. It waits for user input from stdin and will produce some output to stdout or stderr.
-
I understand, I did not know that cmd was different to other executables, such as calc.exe spawning a window. I'll have to find a way to block the main process even if the cmd.exe is started detached. Thank you for your help.