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. WaitForFinished is not working with terminator terminal
Forum Updated to NodeBB v4.3 + New Features

WaitForFinished is not working with terminator terminal

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 873 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.
  • A Offline
    A Offline
    Athena_S
    wrote on last edited by
    #1

    I have a qprocess that is in charge of launching a command to terminator. The problem comes when I use the waitforfinished(-1) function.
    The waitforfinished is supposed to be a function that blocks the thread, but it tells me immediately that the command is finished.
    I have used the connect with the finished signal but the same thing happens.

    On qt version 5.12.9 and ubuntu 16.04 it worked. Now I am on version 5.15.2 and ubuntu 20.04 does not work.

    Does anyone know what can happen?

    JonBJ 1 Reply Last reply
    0
    • A Athena_S

      I have a qprocess that is in charge of launching a command to terminator. The problem comes when I use the waitforfinished(-1) function.
      The waitforfinished is supposed to be a function that blocks the thread, but it tells me immediately that the command is finished.
      I have used the connect with the finished signal but the same thing happens.

      On qt version 5.12.9 and ubuntu 16.04 it worked. Now I am on version 5.15.2 and ubuntu 20.04 does not work.

      Does anyone know what can happen?

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

      @Athena_S
      I would think this would more likely be a change in "Terminator" terminal code across different Ubuntu releases than a Qt code change. QProcess --- or any similar process spawner --- can only look for the exit of the process it initially spawns. If that, for whatever reason, spawns another process and itself exits the caller will see it as "finished".

      Since you say "launching a command to terminator" that does not sound like you need it as an interactive shell. So why use "terminator" at all? What are you trying to run? Can you at least test, say, /bin/sh -c "..." to see if that has any problem waiting for finish?

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Athena_S
        wrote on last edited by Athena_S
        #3

        @JonB
        First of all,
        Thank you for your quick response

        Right now I use the terminator to launch a ros process through a qt application.
        To do this, I launch a qprocess with the following command:

        terminator -m --tittle TITLE -e "command1 && command2 (this last one is the ros node)"
        

        It may be that when I perform the first command, the qprocess terminates the command.

        I use terminator and gnome-terminal, both same problem.

        JonBJ 1 Reply Last reply
        0
        • A Offline
          A Offline
          Athena_S
          wrote on last edited by
          #4

          I have tried launching a single command (sleep 60) and immediately the qProcess is launched, it says it has finished.

          1 Reply Last reply
          0
          • A Athena_S

            @JonB
            First of all,
            Thank you for your quick response

            Right now I use the terminator to launch a ros process through a qt application.
            To do this, I launch a qprocess with the following command:

            terminator -m --tittle TITLE -e "command1 && command2 (this last one is the ros node)"
            

            It may be that when I perform the first command, the qprocess terminates the command.

            I use terminator and gnome-terminal, both same problem.

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

            @Athena_S
            I'm afraid I know nothing about "ros process". I can only assume it is something where you need a visible terminal for something to run in? So you cannot replace with /bin/sh -c?

            So if you go to another terminal and execute the exact same command as you show, when does that finish? E.g.

            terminator -m --tittle TITLE -e "command1 && command2"  ; echo "DONE"
            

            How soon do you see the DONE message? In principle that is when QProcess will see finished signal.

            BTW, are you 100% sure the terminator sub-process runs at all in your new environment. For example, if it could not be found, I don't know what error handling you have in your code to check for this, but it would "finish" immediately.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Athena_S
              wrote on last edited by Athena_S
              #6

              @JonB

              I can't launch in /bin/sh because I have to debug the code and see the terminal

              This is my code. It is a class (ProcessThread) that inherits from qthread and inside launch the qprocess.

              working_directory_ = "/home/user_name"
              time_to_wait_= -1

              void ProcessThread::run()  <<- override from qthread
              {
                process_ = new QProcess();
                process_->setWorkingDirectory(working_directory_);
                process_->start("terminator", args_);
              
                if (!process_->waitForStarted())
                {
                  qDebug() << "Wait for started failed";
                }
                else {
                  qDebug() << "PID " << QString::number(process_->processId());
                  if (!process_->waitForFinished(time_to_wait_))
                  {
                    qDebug() << "The program has finished";
                    kill();
                    is_finished_ = true;
                  }
                  else {
                    qDebug() << "Everything ok! " << windows_name_ ;
                  }
                }
              
              }
              

              I test your echo and i never see, due to ros never "end"

              Christian EhrlicherC 1 Reply Last reply
              0
              • A Athena_S

                @JonB

                I can't launch in /bin/sh because I have to debug the code and see the terminal

                This is my code. It is a class (ProcessThread) that inherits from qthread and inside launch the qprocess.

                working_directory_ = "/home/user_name"
                time_to_wait_= -1

                void ProcessThread::run()  <<- override from qthread
                {
                  process_ = new QProcess();
                  process_->setWorkingDirectory(working_directory_);
                  process_->start("terminator", args_);
                
                  if (!process_->waitForStarted())
                  {
                    qDebug() << "Wait for started failed";
                  }
                  else {
                    qDebug() << "PID " << QString::number(process_->processId());
                    if (!process_->waitForFinished(time_to_wait_))
                    {
                      qDebug() << "The program has finished";
                      kill();
                      is_finished_ = true;
                    }
                    else {
                      qDebug() << "Everything ok! " << windows_name_ ;
                    }
                  }
                
                }
                

                I test your echo and i never see, due to ros never "end"

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Athena_S said in WaitForFinished is not working with terminator terminal:

                This is my code. It is a class (ProcessThread) that inherits from qthread and inside launch the qprocess.

                has nothing to do with your problem but Why?

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

                A 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @Athena_S said in WaitForFinished is not working with terminator terminal:

                  This is my code. It is a class (ProcessThread) that inherits from qthread and inside launch the qprocess.

                  has nothing to do with your problem but Why?

                  A Offline
                  A Offline
                  Athena_S
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher said in WaitForFinished is not working with terminator terminal:

                  has nothing to do with your problem but Why?

                  This is the code that launches the qprocess with the terminator. When it reaches the waitforfinished(), it says that it has finished when it has not really finished.

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • A Athena_S

                    @Christian-Ehrlicher said in WaitForFinished is not working with terminator terminal:

                    has nothing to do with your problem but Why?

                    This is the code that launches the qprocess with the terminator. When it reaches the waitforfinished(), it says that it has finished when it has not really finished.

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Athena_S I said I don't know anything about your problem - but using a QThread to start a QProcess is simply not needed and over-engineered.

                    wrt your problem - I'm on the same with @JonB - I'm pretty sure terminator simply launches a sub-process and exits directly afterwards - there is nothing Qt can do against this. Maybe terminator has a command line switch to avoid this. Or use another console.

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

                    A JonBJ 2 Replies Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @Athena_S I said I don't know anything about your problem - but using a QThread to start a QProcess is simply not needed and over-engineered.

                      wrt your problem - I'm on the same with @JonB - I'm pretty sure terminator simply launches a sub-process and exits directly afterwards - there is nothing Qt can do against this. Maybe terminator has a command line switch to avoid this. Or use another console.

                      A Offline
                      A Offline
                      Athena_S
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher @JonB

                      Okey, I will try with other terminals or come up with another way to do it.

                      Thank you for your quick help.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @Athena_S I said I don't know anything about your problem - but using a QThread to start a QProcess is simply not needed and over-engineered.

                        wrt your problem - I'm on the same with @JonB - I'm pretty sure terminator simply launches a sub-process and exits directly afterwards - there is nothing Qt can do against this. Maybe terminator has a command line switch to avoid this. Or use another console.

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

                        @Christian-Ehrlicher said in WaitForFinished is not working with terminator terminal:

                        I'm on the same with @JonB - I'm pretty sure terminator simply launches a sub-process and exits directly afterwards

                        Yes and No :) The problem is then that from the command line terminator -e "..." ; echo DONE would show the message immediately, which is why I asked the OP, and apparently it does not. We are not finding where the difference between running it from a command-line and running it from QProcess differs. But without the PIDs to see etc. it's hard to guess.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Athena_S
                          wrote on last edited by Athena_S
                          #12

                          @Christian-Ehrlicher @JonB
                          Hi there,
                          I have tested different terminals. The terminal that best "responds" is xfce4-terminal. The problem is: if I don't have any xfce4-terminal launched at first the qprocess works correctly. If by any chance I have launched some xfce4-terminal the qprocess tells me that the process has finished and sets the pid of the process to 0.

                          It is a bit strange.

                          Regards and thanks for the help.

                          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