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 starting on macos only when run from terminal
Forum Updated to NodeBB v4.3 + New Features

QProcess starting on macos only when run from terminal

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 181 Views 3 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.
  • C Offline
    C Offline
    cupboard_
    wrote last edited by
    #1

    windows has no issues
    when ran from terminal ("./test.app/Contents/MacOS/test") also works as expected

    but when i try to run it from the application bundle itself (double clicking test.app) QProcess does not start
    QProcess::errorString() returns "Child process set up failed: execve: No such file or directory" (checked using a dialog window)

    the executable i'm trying to run is in my path and is accessible via the terminal

    proc.start("ffmpeg", QStringList() << "-i" << filename << arguments);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Where is ffmpeg located exactly on your machine ?

      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
      • C Offline
        C Offline
        cupboard_
        wrote last edited by
        #3

        /usr/local/bin/ffmpeg

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote last edited by
          #4

          Add this line before you start the process:

          qInfo() << __FUNCTION__ << proc.processEnvironment();
          

          … to check the process’ environment.
          Looks like /usr/local/bin is in the path of your shell, but not when the app is run from the bundle. See here how to add it.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          2
          • JonBJ Offline
            JonBJ Offline
            JonB
            wrote last edited by JonB
            #5

            @Axel-Spoerl
            If you are proposing calling QProcess::setProcessEnvironment() to change the PATH to include /usr/local/bin for the child, I think there is a 50-50 (or greater?) chance this will not affect the parent's ability to find and run the subprocess. I believe --- but not sure --- that the child process environment only affects what environment the child inherits after it has been spawned successfully. Changing PATH in this way won't help the parent find the child to spawn?

            I think we found this with QProcess::setWorkingDirectory(): you cannot use it in order to spawn some ./executable living in a directory because it is not set before the executable is spawned, it is only set for the child after it has been located and spawned.

            @cupboard_
            If it is an issue finding ffmpeg why don't you start by trying proc.start("/usr/local/bin/ffmpeg", ...)? If that resolves, and QProcess::setProcessEnvironment() does not, you may have to change the PATH in the parent before spawning the child if you want it found via PATH.

            C 1 Reply Last reply
            2
            • JonBJ JonB

              @Axel-Spoerl
              If you are proposing calling QProcess::setProcessEnvironment() to change the PATH to include /usr/local/bin for the child, I think there is a 50-50 (or greater?) chance this will not affect the parent's ability to find and run the subprocess. I believe --- but not sure --- that the child process environment only affects what environment the child inherits after it has been spawned successfully. Changing PATH in this way won't help the parent find the child to spawn?

              I think we found this with QProcess::setWorkingDirectory(): you cannot use it in order to spawn some ./executable living in a directory because it is not set before the executable is spawned, it is only set for the child after it has been located and spawned.

              @cupboard_
              If it is an issue finding ffmpeg why don't you start by trying proc.start("/usr/local/bin/ffmpeg", ...)? If that resolves, and QProcess::setProcessEnvironment() does not, you may have to change the PATH in the parent before spawning the child if you want it found via PATH.

              C Offline
              C Offline
              cupboard_
              wrote last edited by
              #6

              @JonB

              If it is an issue finding ffmpeg why don't you start by trying proc.start("/usr/local/bin/ffmpeg", ...)? If that resolves, and QProcess::setProcessEnvironment() does not, you may have to change the PATH in the parent before spawning the child if you want it found via PATH.

              adding /usr/local/bin to the programs path does not help, calling proc.processEnvironment() returns the updated path, but ffmpeg still doesn't run

              using proc.start("/usr/local/bin/ffmpeg", QStringList() << "-i" << filename << arguments); does work tho

              i tried searching how to change the path in the parent, but i didn't find a way to do it

              JonBJ 1 Reply Last reply
              0
              • C cupboard_

                @JonB

                If it is an issue finding ffmpeg why don't you start by trying proc.start("/usr/local/bin/ffmpeg", ...)? If that resolves, and QProcess::setProcessEnvironment() does not, you may have to change the PATH in the parent before spawning the child if you want it found via PATH.

                adding /usr/local/bin to the programs path does not help, calling proc.processEnvironment() returns the updated path, but ffmpeg still doesn't run

                using proc.start("/usr/local/bin/ffmpeg", QStringList() << "-i" << filename << arguments); does work tho

                i tried searching how to change the path in the parent, but i didn't find a way to do it

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

                @cupboard_ said in QProcess starting on macos only when run from terminal:

                i tried searching how to change the path in the parent, but i didn't find a way to do it

                You would do that by changing the parent/calling process's environment variable PATH. Nothing to do with QProcess, and you would need to do it before trying to do the QProcess::start() of the child. You can use getenv()/putenv() to read/write the parent process's environment variables (e.g. PATH) if you want to examine or change them.

                C 1 Reply Last reply
                1
                • Kent-DorfmanK Offline
                  Kent-DorfmanK Offline
                  Kent-Dorfman
                  wrote last edited by
                  #8

                  ffmpeg also needs access to a bunch of .so libraries. In linux those must be in standard locations or found via the LD_LIBRARY_PATH var. re QProcess::setProcessEnvironment IS the preferred way to make sure the the PATH and LD_LIBRARY_PATH are set properly. Also, QProcess::setWorkingDir is a good idea if the child will reference things by relative path offset.

                  This is the correct way to do it.

                  QProcess process;
                  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
                  env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
                  process.setProcessEnvironment(env);
                  process.start("myapp");
                  

                  So no, @Axel-Spoerl ...the environment is set up BEFORE the child is started.

                  1 Reply Last reply
                  1
                  • JonBJ JonB

                    @cupboard_ said in QProcess starting on macos only when run from terminal:

                    i tried searching how to change the path in the parent, but i didn't find a way to do it

                    You would do that by changing the parent/calling process's environment variable PATH. Nothing to do with QProcess, and you would need to do it before trying to do the QProcess::start() of the child. You can use getenv()/putenv() to read/write the parent process's environment variables (e.g. PATH) if you want to examine or change them.

                    C Offline
                    C Offline
                    cupboard_
                    wrote last edited by
                    #9

                    @JonB said in QProcess starting on macos only when run from terminal:

                    You can use getenv()/putenv() to read/write the parent process's environment variables (e.g. PATH) if you want to examine or change them.

                    thank you, this worked!

                    1 Reply Last reply
                    0
                    • C cupboard_ has marked this topic as solved
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote last edited by
                      #10

                      One other possible option that might also make your users happy: have a setting in your application that allows to set the path to ffmpeg so if they have a custom version they want to use, they can change for it. You can populate that value checking for known paths.

                      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

                      • Login

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