QProcess starting on macos only when run from terminal
-
windows has no issues
when ran from terminal ("./test.app/Contents/MacOS/test") also works as expectedbut 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);
-
Hi,
Where is ffmpeg located exactly on your machine ?
-
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. -
@Axel-Spoerl
If you are proposing callingQProcess::setProcessEnvironment()
to change thePATH
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. ChangingPATH
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 findingffmpeg
why don't you start by tryingproc.start("/usr/local/bin/ffmpeg", ...)
? If that resolves, andQProcess::setProcessEnvironment()
does not, you may have to change thePATH
in the parent before spawning the child if you want it found viaPATH
. -
@Axel-Spoerl
If you are proposing callingQProcess::setProcessEnvironment()
to change thePATH
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. ChangingPATH
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 findingffmpeg
why don't you start by tryingproc.start("/usr/local/bin/ffmpeg", ...)
? If that resolves, andQProcess::setProcessEnvironment()
does not, you may have to change thePATH
in the parent before spawning the child if you want it found viaPATH
.If it is an issue finding
ffmpeg
why don't you start by tryingproc.start("/usr/local/bin/ffmpeg", ...)
? If that resolves, andQProcess::setProcessEnvironment()
does not, you may have to change thePATH
in the parent before spawning the child if you want it found viaPATH
.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 thoi tried searching how to change the path in the parent, but i didn't find a way to do it
-
If it is an issue finding
ffmpeg
why don't you start by tryingproc.start("/usr/local/bin/ffmpeg", ...)
? If that resolves, andQProcess::setProcessEnvironment()
does not, you may have to change thePATH
in the parent before spawning the child if you want it found viaPATH
.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 thoi tried searching how to change the path in the parent, but i didn't find a way to do it
@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 withQProcess
, and you would need to do it before trying to do theQProcess::start()
of the child. You can usegetenv()
/putenv()
to read/write the parent process's environment variables (e.g.PATH
) if you want to examine or change them. -
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.
-
@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 withQProcess
, and you would need to do it before trying to do theQProcess::start()
of the child. You can usegetenv()
/putenv()
to read/write the parent process's environment variables (e.g.PATH
) if you want to examine or change them. -
-
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.