Unsolved How to detect processes that didn't start properly due to nonexistent executable
-
My program runs QProcesses with user defined executables.
Unfortunately, if the executable does not exist, QProcess does not tell me that.I collect all running processes in a vector<shared_ptr<QProcess>> and their
finished
signal is attached to a function that checks that vector and erases all processes whose state is NotRunning. However, the processes whose executable does not exist, do have a state other than NotRunning, also theirfinished
signal is never triggered.How do I get to detect QProcesses which were started with a nonexistent executable?
-
@lp2020 said in How to detect processes that didn't start properly due to nonexistent executable:
Here's a related bug report: https://bugreports.qt.io/browse/QTBUG-5866
That bug was opened in 2009, and never commented on. You have really verified it still applies? And no-one has raised it since?
Do you think that if asking about
QProcess
and behaviour on non-existent executables you should tell us what OS platform you are on? -
No, I think I mixed up something regarding that bug. Also I run my Process with
start(cmd)
and notexecute
which doesn't return anything. I'm going to edit it out of the question.
Unfortunately, the mentionedfinished
signal never gets triggered for these special cases.Sorry for not providing my OS.
OS: Ubuntu 20.04 LTS x86_64 Kernel: 5.4.0-39-generic DE: Plasma
-
I would guess that QProcess::state() will be QProcess::NotRunning and error() is QProcess::FailedToStart in this case directly after the call of start().
Since the process never runs, the signal 'finished()' can't be called. -
@lp2020
Follow what @Christian-Ehrlicher has said.You have found
QProcess::finished()
signal for yourself; you need to look atstarted()
&errorOccurred()
signals in combination withfinished()
.Separately, do you really have to detect
Unfortunately, if the executable does not exist, QProcess does not tell me that.
How do I get to detect QProcesses which were started with a nonexistent executable?It can be done, but there will be quite a lot of possibilities for detecting "executable does not exist". For a start, do you execute by full path to executable or plain name to be found on
PATH
? Many other questions. So let us know what exactly you need to detect about a non-runnable, if that's important. -
Thank you for your answers.
error() is QProcess::FailedToStart
This was what I'm looking for. If someone stumbles upon this, it takes a small while until this error is detected - don't check for it in the command next to the start() code. I used
process->waitForStarted(100);
to make sure it gets detected.For a start, do you execute by full path to executable or plain name to be found on PATH? Many other questions. So let us know what exactly you need to detect about a non-runnable, if that's important.
It can be any error, the executable not being in the path, the full path being wrong, something not properly installed etc. as I mentioned it's user defined and users can enter paths or executables, correct or wrong.
-
@lp2020
The best way to write this code is withQProcess
signals/slots, instead of using the various blockingwaitFor...()
methods.