I need some help with this: I want to start a script ("test.sh") from inside my code and read the output. The script is giving an output string in an interval of 3 seconds for 5 times. So the output string is generated 5 times with a pause of 3 seconds in between. I want to display the output strings in a QTextBrowser. The string should be added every 3 seconds (as it comes from the script). Therefore I connected the readyReadStandardOutput() signal from QProcess to a slot but this slot is never entered. The connect function returns true. So no problem there, I guess. There is some code:
void DialogWindow::startScript()
{
QProcess* prcs = new QProcess(this);
connect(prcs, SIGNAL(readyReadStandardOutput()), this, SLOT(slot_readyReadStandardOutput()));
QString program = "./test.sh";
prcs->setProgram(program);
prcs->open();
if(prcs->isOpen())
prcs->execute("test.sh"); //this line is executed
prcs->waitForStarted(6000);
qDebug() << prcs->state(); // --> "QProcess::NotRunning"
qDebug() << prcs->error(); // --> "QProcess::FailedToStart"
qDebug() << prcs->errorString(); // --> "0x000000c1"
qDebug() << prcs->workingDirectory(); // --> ""
}
void DialogWindow::slot_readyReadStandardOutput()
{
QTextBrowser* m_pTextBrowser = new QTextBrowser();
prcs->readAllStandardOutput();
prcs->readAllStandardError();
QString output = prcs->readAllStandardOutput();
if(output.contains("warning"))
m_pTextBrowser->setTextColor(QColor(Qt::yellow));
if(output.contains("error"))
{
m_pTextBrowser->setTextColor(QColor(Qt::red));
//emit errorOccured();
}
m_pTextBrowser->append(prcs->readAllStandardOutput());
m_pTextBrowser->setTextColor(QColor(Qt::black));
}
What am I missing???? My script is located in my project folder and I copied it to the debug folder. The script is running properly and returns the output text as expected when double clicking it or using the command "./test.sh" in the shell.
UPDATE: I could figure out which error string I get (0x000000c1) and I looked it up here. It means: ERROR_BAD_EXE_FORMAT / %1 is not a valid Win32 application
What does that mean? The script is running as described above... Why can I not start it with QProcess?