Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QProcess doesn't emit finished signal when script completes its execution

    General and Desktop
    qprocess zombie finished return slot
    4
    9
    6954
    Loading More Posts
    • 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.
    • D
      diredko last edited by diredko

      Hi All,
      I'm having troubles with running separate script from Qt application using QProcess.
      The problem is that for some reason slot for finished signal is not invoked after the script has finished its activities.
      The launched script becomes a zombie process.

      I'm running the script as follows:

      process = new QProcess();
      
      connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onOutput()));
      
      connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int,QProcess::ExitStatus)));
      
      process->start("some_script.sh");
      

      I tried to run script itself in terminal and it didn't stuck and returned fine.
      readyReadStandardOutput() is emitted when new output is generated by script and onOutput() slot is invoked.

      Would someone please please provide any thoughts on what might be done wrong here? I would appreciate any suggestion.

      Thanks in advance.

      P.S. I'm not sure if this is relevant but the application runs in QNX OS. Qt Version - 5.5.1

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        hi
        On windows so cant test.
        Have you tried
        QProcess sh;
        sh.start("sh", QStringList() << "-c" << "/path/some_script.sh");

        That i use for running a bat file in windows.
        (well its "/c")

        The some_script.sh is not the process it self, a shell will also indirectly be opened.
        So I wonder if that shell remains open.

        D 1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          You should also check the error output.

          Note that you try to start "some_script.sh" which is a relative path so you are likely not even starting it unless you copied it in the same folder where the application got built (Qt Creator shadow build).

          One way to validate that is to put the fullpath to the script in the QProcess::start call.

          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 Reply Quote 0
          • D
            diredko last edited by

            Thanks for your suggestion,
            The the path to script is absolute. I'm sure.
            I have tried to run the following script and faced same problem:

            #!/bin/sh
            
            sleep 1
            echo "TEST MESSAGE 1"
            
            sleep 2
            echo "TEST MESSAGE 2" 
            
            sleep 1
            echo "TEST MESSAGE 3" 
            
            sleep 1
            echo "TEST MESSAGE 4"
            
            sleep 1
            
            exit 0
            

            Finished signal is not coming

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              That: process->start("some_script.sh"); is not an absolute path.

              Did you check that you get anything ? What about using waitForStarted ?

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

              D 1 Reply Last reply Reply Quote 0
              • D
                diredko @mrjj last edited by

                @mrjj thanks for your suggestion, unfortunately it didn't help

                1 Reply Last reply Reply Quote 0
                • D
                  diredko @SGaist last edited by

                  @SGaist I used "some_script.sh" just to make a point that a script is being passed to QProcess. the actual path is /home/user_name/programDevice.sh. I'm sure that script is being executed since it's output is being displayed in my app GUI

                  1 Reply Last reply Reply Quote 0
                  • Paul Colby
                    Paul Colby last edited by

                    Hi @diredko,

                    I merged your code into an existing project for a quick test (on Ubuntu 15.10), and it worked as expected:

                    MainWizard::MainWizard(QWidget *parent, Qt::WindowFlags flags): QWizard(parent,flags) {
                        QProcess * const process = new QProcess();
                        connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onOutput()));
                        connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int,QProcess::ExitStatus)));
                        process->start("sh", QStringList() << "-c" << "/home/paul/some_script.sh");
                    }
                    
                    void MainWizard::onOutput()
                    {
                        qDebug() << __func__ << qobject_cast<QProcess *>(sender())->readAllStandardOutput();
                    }
                    
                    void MainWizard::onFinished(int code, QProcess::ExitStatus status)
                    {
                        qDebug() << __func__ << code << status;
                    }
                    

                    Output:

                    onOutput "TEST MESSAGE 1
                    "
                    onOutput "TEST MESSAGE 2
                    "
                    onOutput "TEST MESSAGE 3
                    "
                    onOutput "TEST MESSAGE 4
                    "
                    onFinished 0 0
                    

                    Can you provide a complete, cut-down example that exhibits the problem? Otherwise, at least the show us the main function, the class that owns the QProcess pointer and slots, and the code that instantiates an instance of that class.

                    Then I'll test that out, and see if I can reproduce the issue :)

                    Cheers.

                    1 Reply Last reply Reply Quote 0
                    • D
                      diredko last edited by

                      Hi,
                      Thanks for your response. The whole body of code is proprietary so I'm not sure I can share it in a public forum.
                      However I can make a note that it used to work fine a month ago and after that no changes occurred to this code and no qt libraries were replaced, so the issue is like to be caused by hardware malfunction.

                      Thanks again ))

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post