I compiled a c++ source file from the Qt app I am creating. Now I want to run the exe file generated and also to redirect its input and output to txt files. But when I try to run it from QProcess, it fails to execute with exit code -2.
This is how I compiled the file using QProcess -
arguments << fileName << "-o" << exeFileName << "-static";
connect(compileProcess, SIGNAL(finished(int)), this, SLOT(compiled()));
compileProcess->start(QString("g++"), arguments);
And this is how I run the exe from QProcess in the slot compiled() -
runProcess->setStandardInputFile(inputFilename);
runProcess->setStandardOutputFile(QFileInfo(exeFileName).path() + "/output.txt");
int code = runProcess->execute(exeFileName); //code = -2
The program runs fine when I start it manually. So, why can't it be started from QProcess? I am working with Qt 5.0.2 on Windows 7
This is the source file I am compiling -
#include <iostream>
int main() {
std::string s;s
std::cin >> s;
std::cout << s;
return 0;
}
readAllStandardErrorand print the contents, does it have any information? The-2is usually it fails to either open the executable with the correct permissions, or it can't find the executable so also double check that theexeFileNameis pointing to the correct place. - Nicholas SmithreadAllStandardErrordoesn't return any information. And I verified thatexeFileNamepoints to the correct file. - ShubhamexeFileNamepath. - Nicholas SmithexeFileNamehas the absolute path to the file, even then QProcess can't find the file? - Shubham