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. QProcess doesn't emit finished signal when script completes its execution
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprocesszombiefinishedreturnslot
9 Posts 4 Posters 7.9k Views
  • 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 Offline
    D Offline
    diredko
    wrote on last edited by diredko
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        0
        • D Offline
          D Offline
          diredko
          wrote on last edited by
          #4

          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
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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
            0
            • mrjjM 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 Offline
              D Offline
              diredko
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • SGaistS SGaist

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

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

                D Offline
                D Offline
                diredko
                wrote on last edited by
                #7

                @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
                0
                • Paul ColbyP Offline
                  Paul ColbyP Offline
                  Paul Colby
                  wrote on last edited by
                  #8

                  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
                  0
                  • D Offline
                    D Offline
                    diredko
                    wrote on last edited by
                    #9

                    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
                    0

                    • Login

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