Get QProcess output
-
Hello felow Qt programmers
How can I get output of external application which was started in command line console via QProcess::startDetached("cmd", args, workingDir)?
The problem is in case of error console is closed immediately, and I can't see what's wrong. Morever, the "/K" switch seems to not work:args << "/K" << "start" << "the app to be started in console";
From what I've found in google I need inter process communication, but I failed to get any meaningful details how to redirect stdout and stderr into my Qt application.
-
@MasterBLB Did you connect slots to https://doc.qt.io/qt-5/qprocess.html#readyReadStandardError and https://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput ?
-
Apart from what @jsulm said you must not use startDetached if you want to read stdout/stderr from the process.
-
startDetached() is a must as it turned out, otherwise the cmd with injected command won't work correctly.
Reading standard error and output based on readiness signals worked, but not the way I need - the output is buffered and flushed each few seconds, while I need each byte of data available immediately, so I was forced to abandon that solution. -
@MasterBLB
I don't understand what you are trying to achieve withcmd /K start ...
? And if you're going to callstart
I don't see how you think any amount of stdout/stderr redirection will have the slightest effect (99% sure that withstart
there is no carry-over of std-streams), or for that matter why you then needstartDetached()
.If you need IPC for this that is a quite separate matter....
-
Why is "cmd /K start" needed at all?