Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error reading readAll StandardOutput()
Forum Updated to NodeBB v4.3 + New Features

Error reading readAll StandardOutput()

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 5 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • e.ferroE Offline
    e.ferroE Offline
    e.ferro
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      It is likely that you did not use QProcess pointer. Can you please show your code?

      e.ferroE 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        From the looks of it, you likely did not let the process properly finish.

        Can you show your code ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          It is likely that you did not use QProcess pointer. Can you please show your code?

          e.ferroE Offline
          e.ferroE Offline
          e.ferro
          wrote on last edited by e.ferro
          #4

          @JoeCFD @SGaist

          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);
          

          }

          JoeCFDJ JonBJ 2 Replies Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            e.ferroE 1 Reply Last reply
            0
            • e.ferroE e.ferro

              @JoeCFD @SGaist

              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);
              

              }

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

              @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

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                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.

                e.ferroE Offline
                e.ferroE Offline
                e.ferro
                wrote on last edited by
                #7

                @Christian-Ehrlicher

                Sorry 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.

                1 Reply Last reply
                0
                • e.ferroE Offline
                  e.ferroE Offline
                  e.ferro
                  wrote on last edited by
                  #8

                  Follow image. The process is destroyed but the eeprom recording continues normally

                  Captura de tela de 2022-06-13 16-27-44.png

                  1 Reply Last reply
                  0
                  • JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by
                    #9

                    @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

                    e.ferroE 1 Reply Last reply
                    0
                    • e.ferroE Offline
                      e.ferroE Offline
                      e.ferro
                      wrote on last edited by
                      #10

                      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()

                      JoeCFDJ 1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @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

                        e.ferroE Offline
                        e.ferroE Offline
                        e.ferro
                        wrote on last edited by
                        #11

                        @JoeCFD

                        Sorry, could you give me an example? I put it in the main window and it gives me an error

                        1 Reply Last reply
                        0
                        • e.ferroE e.ferro

                          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()

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by JoeCFD
                          #12

                          @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);
                             }
                          }
                          
                          e.ferroE 1 Reply Last reply
                          0
                          • e.ferroE e.ferro

                            @JoeCFD @SGaist

                            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);
                            

                            }

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @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 for flashrom to exit to indicate it has finished doing whatever reading/writing it does.

                            1 Reply Last reply
                            0
                            • JoeCFDJ 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);
                                 }
                              }
                              
                              e.ferroE Offline
                              e.ferroE Offline
                              e.ferro
                              wrote on last edited by e.ferro
                              #14

                              @JoeCFD @JonB Still the same error, look at the output running from Ubuntu terminal and running from Qt

                              Captura de tela de 2022-06-13 17-41-22.png

                              Captura de tela de 2022-06-13 17-51-18.png

                              JonBJ 1 Reply Last reply
                              0
                              • JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on last edited by
                                #15

                                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.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  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.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  JoeCFDJ SGaistS 2 Replies Last reply
                                  0
                                  • SGaistS SGaist

                                    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.

                                    JoeCFDJ Offline
                                    JoeCFDJ Offline
                                    JoeCFD
                                    wrote on last edited by
                                    #17

                                    @SGaist right. Simply set more seconds

                                    if ( true == process->waitForFinished(10000 ) ) { /*add to 10s or more */
                                        QString word = process->readAllStandardOutput();
                                        ui->textEdit->setText(word);
                                    }
                                    
                                    1 Reply Last reply
                                    1
                                    • e.ferroE e.ferro

                                      @JoeCFD @JonB Still the same error, look at the output running from Ubuntu terminal and running from Qt

                                      Captura de tela de 2022-06-13 17-41-22.png

                                      Captura de tela de 2022-06-13 17-51-18.png

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #18

                                      @e-ferro
                                      I asked for output of the result of process.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 the QProcess 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.

                                      1 Reply Last reply
                                      0
                                      • e.ferroE Offline
                                        e.ferroE Offline
                                        e.ferro
                                        wrote on last edited by
                                        #19

                                        Now it works with the command

                                        process.waitForFinished(-1);

                                        The difference is that the log message only appears after the end of the process and the program is frozen, but it works perfectly. But now I put a message for the user to wait. Thanks a lot guys for the help!!

                                        Captura de tela de 2022-06-14 11-28-57.png

                                        1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          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.

                                          SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          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.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved