Error reading readAll StandardOutput()
-
wrote on 13 Jun 2022, 18:12 last edited by
I'm running a command through QProcess and executing readAll StandardOutput(), it executes and then finishes showing the message QProcess: Destroyed while process ("/bin/sh") is still running. The process that was called continues but I cannot read further. I'm using linux.
-
wrote on 13 Jun 2022, 19:03 last edited by
It is likely that you did not use QProcess pointer. Can you please show your code?
-
Hi,
From the looks of it, you likely did not let the process properly finish.
Can you show your code ?
-
wrote on 13 Jun 2022, 19:08 last edited by e.ferro
void MainWindow::on_pushButton_2_clicked(){ QProcess process; QStringList command; command << "flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom "; process.start("/bin/sh", QStringList()<< "-c" << command); process.waitForFinished(); QString word = process.readAllStandardOutput(); ui->textEdit->setText(word);
}
-
I really wonder why everyone thinks a shell is needed just to execute a program. Is this somewhere in the Qt docs or so?
Don't use /bin/sh and execute flashrom directly.
-
void MainWindow::on_pushButton_2_clicked(){ QProcess process; QStringList command; command << "flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom "; process.start("/bin/sh", QStringList()<< "-c" << command); process.waitForFinished(); QString word = process.readAllStandardOutput(); ui->textEdit->setText(word);
}
wrote on 13 Jun 2022, 19:12 last edited by JoeCFD@e-ferro
if ( true == process.waitForFinished() ) { QString word = process.readAllStandardOutput(); ui->textEdit->setText(word); } or if ( true == process.waitForFinished(6000 ) ) { /*add 6s whatever you need */ QString word = process.readAllStandardOutput(); ui->textEdit->setText(word); }
Christian is right. Run the script directly. I did not pay attention to it. set all of them "-p" "serprog:dev=/dev/ttyACM0:115200" "-r" "/home/ti/Downloads/uno.rom" to string list as arguments
-
I really wonder why everyone thinks a shell is needed just to execute a program. Is this somewhere in the Qt docs or so?
Don't use /bin/sh and execute flashrom directly.
wrote on 13 Jun 2022, 19:20 last edited bySorry sir, I'm new to qt world and I'm trying to learn to make a project with Flashrom + Arduino. Everywhere I look for how to read the Terminal, I only find it that way. If I can help, I'm willing to learn.
-
wrote on 13 Jun 2022, 19:33 last edited by
-
wrote on 13 Jun 2022, 19:41 last edited by
@e-ferro said in Error reading readAll StandardOutput():
QProcess process;
create a process pointer inside MainWindow
m_process = new QProcess;
delete it in the destructor -
wrote on 13 Jun 2022, 19:49 last edited by
Using command:
process.startCommand("flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom ");
removing /bin/sh
the message stays
QProcess: Destroyed while process ("flashrom") is still running.
If I start with startDetached
The entire log of the operation appears in the Application Output but is not read by readAllStandardOutput()
-
@e-ferro said in Error reading readAll StandardOutput():
QProcess process;
create a process pointer inside MainWindow
m_process = new QProcess;
delete it in the destructor -
Using command:
process.startCommand("flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom ");
removing /bin/sh
the message stays
QProcess: Destroyed while process ("flashrom") is still running.
If I start with startDetached
The entire log of the operation appears in the Application Output but is not read by readAllStandardOutput()
wrote on 13 Jun 2022, 20:07 last edited by JoeCFD@e-ferro
class MainWindow : public QMainWindow { ... your stuff... private: QProcess * m_process{}; }; void MainWindow::on_pushButton_2_clicked(){ if ( nullptr == _process ) { m_process = new QProcess; } m_process->start(...); if ( true == process->waitForFinished() ) { QString word = m_process->readAllStandardOutput(); ui->textEdit->setText(word); } }
-
void MainWindow::on_pushButton_2_clicked(){ QProcess process; QStringList command; command << "flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom "; process.start("/bin/sh", QStringList()<< "-c" << command); process.waitForFinished(); QString word = process.readAllStandardOutput(); ui->textEdit->setText(word);
}
wrote on 13 Jun 2022, 20:43 last edited by JonB@e-ferro said in Error reading readAll StandardOutput():
process.waitForFinished();
Let's establish what this is returning:
bool result = process.waitForFinished(); qDebug() << "waitForFinished:" << result;
Because it sounds like that is returning false, then the
QProcess process
would go out of scope while the process is still running and hence the error message.One question: if you go into a terminal, type your
flashrom -p ...
command, I can see it runs up a UI. If you run this from a shell in a terminal, does the command complete immediately and show the next line's shell prompt while the UI is still being shown? If so that means in any case you cannot wait forflashrom
to exit to indicate it has finished doing whatever reading/writing it does. -
@e-ferro
class MainWindow : public QMainWindow { ... your stuff... private: QProcess * m_process{}; }; void MainWindow::on_pushButton_2_clicked(){ if ( nullptr == _process ) { m_process = new QProcess; } m_process->start(...); if ( true == process->waitForFinished() ) { QString word = m_process->readAllStandardOutput(); ui->textEdit->setText(word); } }
-
wrote on 13 Jun 2022, 21:05 last edited by
how long does it take to run your script? If long, throw it into a thread and set the time longer. The default time is 3s.
-
There is no need for a thread. QProcess is asynchronous already so if the operation takes a long time, just exploit properly this asynchronous nature.
-
There is no need for a thread. QProcess is asynchronous already so if the operation takes a long time, just exploit properly this asynchronous nature.
-
wrote on 14 Jun 2022, 07:04 last edited by JonB
@e-ferro
I asked for output of the result ofprocess.waitForFinished()
, which you do not show.The answer looks quite simple anyway. You have never said how long it takes for the flashrom to run, till you see the
QProcess: Destroyed while process ("/bin/sh") is still running
message. If you had said "flashrom takes quite some time to run, and I see that message after 30 seconds", we would have known immediately.bool QProcess::waitForFinished(int msecs = 30000) waits by default for 30 seconds for the sub-process to finish. If it has not finished by then it returns false (operation timed out) and then your code continues executing. When your code exits the
on_pushButton_2_clicked()
slot theQProcess process
variable goes out of scope, and you will get that warning message because the sub-process is still running.Assuming you want your Qt program to simply do nothing and wait until the flashrom application exits, you should call:
process.waitForFinished(-1);
Now you will get its complete output and not get that warning message.
Be aware that the user will not be able to do anything at all in your Qt application while it is waiting like this. I am guessing this is fine by you. If you do want the user be able to do other things in your app while flashrom is running, you would have to change to using signals and slots.
-
wrote on 14 Jun 2022, 14:29 last edited by
-
There is no need for a thread. QProcess is asynchronous already so if the operation takes a long time, just exploit properly this asynchronous nature.
Then as suggested before, you should take advantage of the asynchronous nature of QProcess so your users won't be in front of a frozen UI maybe a disabled one but not frozen.
1/20