I need to run a custom executable in my application. I have the following code to run my process:
QFileInfo fiUpdator(updatorLocation);
if(!fiUpdator.isExecutable()) {
qWarning() << "Maintenance Tool is not an executable";
return;
}
qDebug() << "Starting updator app";
QString pid = QString::number(qApp->applicationPid());
QString appName = qApp->applicationName();
QProcess *p = new QProcess;
connect(p, &QProcess::started, this, [this](){
qDebug() << "Updator Process Started";
});
connect(p, &QProcess::errorOccurred, this, [this](QProcess::ProcessError error){
qDebug() << "Error Occurred : " << error;
});
connect(p, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this, p](){
qDebug() << "Finished Updator Process";
QString str("Exit [" + QString::number(p->exitCode()) + "] " + p->exitStatus());
qDebug() << str;
});
connect(p, &QProcess::readyReadStandardError, this, [this, p](){
QByteArray ba = p->readAllStandardError();
qDebug() << "Error:\n" << QString::fromUtf8(ba);
});
connect(p, &QProcess::readyReadStandardOutput, this, [this, p](){
QByteArray ba = p->readAllStandardOutput();
qDebug() << "Output:\n" << QString::fromUtf8(ba);
});
connect(p, &QProcess::stateChanged, this, [this](QProcess::ProcessState newState){
qDebug() << "State Changed : " << newState;
});
p->start(
updatorLocation,
QStringList()
<< pid
<< appName
<< newFilePath
<< oldFilePath);
The application (a qt console application) runs as expected using
start "" "C:\Path\To\AwesomeConsoleApp.exe"
which briefly opens a new CMD window with the coded output, alternatively opening cmd.exe and running
C:\Path\To\AwesomeConsoleApp.exe
displays the output to stdout in the same cmd window.
The process signal fire as follows:
stateChanged StartingstateChanged RunningQProcess::startedstateChanged NotRunningQProcess::finished: outputExit[1] 0
I tried replacing the .exe to launch with C:\Windows\System32\calc.exe and it launched with no problem.
Does this mean there is something wrong with my custom executable?