Unsolved waitforstarted returning true on a false command
-
so i am starting a qprocess with a wrong command to check if my error handeling is correct my problem is waitforstarted function returns true and the process have a pid for a moment is that normal
-
@Dijkstra From the documentation: "Note: On some UNIX operating systems, this function may return true but the process may later report a QProcess::FailedToStart error."
https://doc.qt.io/qt-5/qprocess.html#waitForStarted
On what OS are you? -
@jsulm ubuntu
connect(&plugin_process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) { qDebug() << "error running " <<getname()<<' '<< error << endl; if(processed_frames<get_frames()) emit(error_stop()); return; }); plugin_process.start("/bin/bash",QStringList() << "-c" << runCmd); bool started=plugin_process.waitForStarted(); if(!started){ std::cout<<"failed to start process"<<std::endl; emit(error_stop()); return; }
and this is what i am talking about this command will run a json file that doesnt exist my problem is that the error is not catched and the waitforstarted returns true
-
@Dijkstra You're starting bash, so why should that fail? That the application running in bash fails doesn't matter as your QProcess is starting bash...
-
@Dijkstra said in waitforstarted returning true on a false command:
will run a json file
[In addition to @jsulm, who is absolutely correct about the
bash
will run.] What do you mean by "run" a JSON file? JSON files are data, they don't "run" or "execute" anyway. Till we know what you actually mean it's hard to suggest a solutuon. -
@jsulm the process ends immediatly and the pid doesnt exist anymore but for a brief second their is a pid should i delay a second before checking the pid ? or what do you think should be done
-
@Dijkstra There is no issue: it behaves as it should. You start bash and ask it to start a non-existent app. That means the process starts successfully (bash), but bash cannot execute what you asked it to execute, so it terminates. So, I don't know what you want to do now...
-
@JonB not a json file sorry i am running a certain exe file on my system that takes a json file
-
@Dijkstra said in waitforstarted returning true on a false command:
@JonB not a json file sorry i am running a certain exe file on my system that takes a json file
OK, that's better! And as I imagined. The problem is: the lack of a data file for some executable is not going to cause any kind of
QProcess::errorOccurred
. The executable will start fine, then it will issue an error message and exit with a non-zero status (if it's well-behaved). So anything to do withQProcess::waitForStarted()
is never going to tell you that. Hence why I asked. That is only going to be detectable by examining the exit code after completion.[I assume by "this command will run a json file that doesnt exist " you meant the JSON file does not exist, not the command/executable does not exist. Whereas @jsulm is taking you to say the reverse. But who knows, since you don't make that clear.]
If you want help on this, you had better give the command you're actually running and explain what you want to trap/test for.....