I have a simple piece of code that runs an external script (see below). The code runs great. Now I want to set an environment variable before running the script. When I do, the waitForStarted method fails with error code 0 and errorString "Exec format error".
I've simplified my code, and can reproduce the error simply by calling setProcessEnvironment. On the code below, if I comment out the third line it runs great. if I uncomment the third line I get the error noted above. Can someone explain why simply setting the environment back to what it was would cause this error? (Running on Linux in case it matters, with Qt 5.1.0).
QProcess command;
QProcessEnvironment oldenvironment = QProcessEnvironment::systemEnvironment();
// If I comment out next line it runs fine!
command.setProcessEnvironment(oldenvironment);
command.start(commandpath, parameters);
if (command.waitForStarted(START_WAIT_TIME)) {
qDebug() << "Started ok";
} else {
qDebug() << "*** start error code: " << command.error();
qDebug() << "*** start error string: " << command.errorString();
}
As well, commandpath is set to "/tmp/myscript.sh" and parameters is an empty QStringList