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 Offline
    E Offline
    e.ferro
    wrote on 13 Jun 2022, 18:12 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
    • J Offline
      J Offline
      JoeCFD
      wrote on 13 Jun 2022, 19:03 last edited by
      #2

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

      E 1 Reply Last reply 13 Jun 2022, 19:08
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 13 Jun 2022, 19:04 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
        • J JoeCFD
          13 Jun 2022, 19:03

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

          E Offline
          E Offline
          e.ferro
          wrote on 13 Jun 2022, 19:08 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);
          

          }

          J J 2 Replies Last reply 13 Jun 2022, 19:12
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 13 Jun 2022, 19:11 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 1 Reply Last reply 13 Jun 2022, 19:20
            0
            • E e.ferro
              13 Jun 2022, 19:08

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

              }

              J Offline
              J Offline
              JoeCFD
              wrote on 13 Jun 2022, 19:12 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
              • C Christian Ehrlicher
                13 Jun 2022, 19:11

                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 Offline
                E Offline
                e.ferro
                wrote on 13 Jun 2022, 19:20 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 Offline
                  E Offline
                  e.ferro
                  wrote on 13 Jun 2022, 19:33 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
                  • J Offline
                    J Offline
                    JoeCFD
                    wrote on 13 Jun 2022, 19:41 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 1 Reply Last reply 13 Jun 2022, 20:03
                    0
                    • E Offline
                      E Offline
                      e.ferro
                      wrote on 13 Jun 2022, 19:49 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()

                      J 1 Reply Last reply 13 Jun 2022, 20:07
                      0
                      • J JoeCFD
                        13 Jun 2022, 19:41

                        @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 Offline
                        E Offline
                        e.ferro
                        wrote on 13 Jun 2022, 20:03 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 e.ferro
                          13 Jun 2022, 19:49

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

                          J Offline
                          J Offline
                          JoeCFD
                          wrote on 13 Jun 2022, 20:07 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 1 Reply Last reply 13 Jun 2022, 20:51
                          0
                          • E e.ferro
                            13 Jun 2022, 19:08

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

                            }

                            J Offline
                            J Offline
                            JonB
                            wrote on 13 Jun 2022, 20:43 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
                            • J JoeCFD
                              13 Jun 2022, 20:07

                              @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 Offline
                              E Offline
                              e.ferro
                              wrote on 13 Jun 2022, 20:51 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

                              J 1 Reply Last reply 14 Jun 2022, 07:04
                              0
                              • J Offline
                                J Offline
                                JoeCFD
                                wrote on 13 Jun 2022, 21:05 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
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 13 Jun 2022, 21:16 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

                                  J S 2 Replies Last reply 13 Jun 2022, 22:33
                                  0
                                  • S SGaist
                                    13 Jun 2022, 21: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.

                                    J Offline
                                    J Offline
                                    JoeCFD
                                    wrote on 13 Jun 2022, 22:33 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 e.ferro
                                      13 Jun 2022, 20:51

                                      @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

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 14 Jun 2022, 07:04 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 Offline
                                        E Offline
                                        e.ferro
                                        wrote on 14 Jun 2022, 14:29 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
                                        • S SGaist
                                          13 Jun 2022, 21: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.

                                          S Offline
                                          S Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 14 Jun 2022, 14:46 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

                                          1/20

                                          13 Jun 2022, 18:12

                                          • Login

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