Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

WaitForFinished is not working with terminator terminal



  • 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?



  • @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?



  • @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.



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



  • @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.



  • @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"


  • Lifetime Qt Champion

    @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?



  • @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.


  • Lifetime Qt Champion

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



  • @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.



  • @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.



  • @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.


Log in to reply