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. How to detect processes that didn't start properly due to nonexistent executable
Forum Updated to NodeBB v4.3 + New Features

How to detect processes that didn't start properly due to nonexistent executable

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 647 Views 1 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.
  • L Offline
    L Offline
    lp2020
    wrote on last edited by lp2020
    #1

    My program runs QProcesses with user defined executables.
    Unfortunately, if the executable does not exist, QProcess does not tell me that.

    I collect all running processes in a vector<shared_ptr<QProcess>> and their finished signal is attached to a function that checks that vector and erases all processes whose state is NotRunning. However, the processes whose executable does not exist, do have a state other than NotRunning, also their finished signal is never triggered.

    How do I get to detect QProcesses which were started with a nonexistent executable?

    JonBJ 1 Reply Last reply
    0
    • L lp2020

      My program runs QProcesses with user defined executables.
      Unfortunately, if the executable does not exist, QProcess does not tell me that.

      I collect all running processes in a vector<shared_ptr<QProcess>> and their finished signal is attached to a function that checks that vector and erases all processes whose state is NotRunning. However, the processes whose executable does not exist, do have a state other than NotRunning, also their finished signal is never triggered.

      How do I get to detect QProcesses which were started with a nonexistent executable?

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

      @lp2020 said in How to detect processes that didn't start properly due to nonexistent executable:

      Here's a related bug report: https://bugreports.qt.io/browse/QTBUG-5866

      That bug was opened in 2009, and never commented on. You have really verified it still applies? And no-one has raised it since?

      Do you think that if asking about QProcess and behaviour on non-existent executables you should tell us what OS platform you are on?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lp2020
        wrote on last edited by
        #3

        No, I think I mixed up something regarding that bug. Also I run my Process with start(cmd) and not execute which doesn't return anything. I'm going to edit it out of the question.
        Unfortunately, the mentioned finished signal never gets triggered for these special cases.

        Sorry for not providing my OS.

        OS: Ubuntu 20.04 LTS x86_64 
        Kernel: 5.4.0-39-generic
        DE: Plasma
        
        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I would guess that QProcess::state() will be QProcess::NotRunning and error() is QProcess::FailedToStart in this case directly after the call of start().
          Since the process never runs, the signal 'finished()' can't be called.

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

          1 Reply Last reply
          3
          • L lp2020

            No, I think I mixed up something regarding that bug. Also I run my Process with start(cmd) and not execute which doesn't return anything. I'm going to edit it out of the question.
            Unfortunately, the mentioned finished signal never gets triggered for these special cases.

            Sorry for not providing my OS.

            OS: Ubuntu 20.04 LTS x86_64 
            Kernel: 5.4.0-39-generic
            DE: Plasma
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @lp2020
            Follow what @Christian-Ehrlicher has said.

            You have found QProcess::finished() signal for yourself; you need to look at started() & errorOccurred() signals in combination with finished().

            Separately, do you really have to detect

            Unfortunately, if the executable does not exist, QProcess does not tell me that.
            How do I get to detect QProcesses which were started with a nonexistent executable?

            It can be done, but there will be quite a lot of possibilities for detecting "executable does not exist". For a start, do you execute by full path to executable or plain name to be found on PATH? Many other questions. So let us know what exactly you need to detect about a non-runnable, if that's important.

            1 Reply Last reply
            2
            • L Offline
              L Offline
              lp2020
              wrote on last edited by
              #6

              Thank you for your answers.

              error() is QProcess::FailedToStart

              This was what I'm looking for. If someone stumbles upon this, it takes a small while until this error is detected - don't check for it in the command next to the start() code. I used process->waitForStarted(100); to make sure it gets detected.

              For a start, do you execute by full path to executable or plain name to be found on PATH? Many other questions. So let us know what exactly you need to detect about a non-runnable, if that's important.

              It can be any error, the executable not being in the path, the full path being wrong, something not properly installed etc. as I mentioned it's user defined and users can enter paths or executables, correct or wrong.

              JonBJ 1 Reply Last reply
              0
              • L lp2020

                Thank you for your answers.

                error() is QProcess::FailedToStart

                This was what I'm looking for. If someone stumbles upon this, it takes a small while until this error is detected - don't check for it in the command next to the start() code. I used process->waitForStarted(100); to make sure it gets detected.

                For a start, do you execute by full path to executable or plain name to be found on PATH? Many other questions. So let us know what exactly you need to detect about a non-runnable, if that's important.

                It can be any error, the executable not being in the path, the full path being wrong, something not properly installed etc. as I mentioned it's user defined and users can enter paths or executables, correct or wrong.

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

                @lp2020
                The best way to write this code is with QProcess signals/slots, instead of using the various blocking waitFor...() methods.

                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