We can run a process foo
with help of System.Process.proc
as follows:
createProcess $ proc "foo" []
However we do not know ahead of time whether foo
can be found. We could run it and catch an exception but that's poor. We could also first call out to which
but that also sucks. In the process
library we find RawCommand
which as of today says
The FilePath argument names the executable, and is interpreted according to the platform's standard policy for searching for executables. Specifically:
on Unix systems the execvp(3) semantics is used, where if the executable filename does not contain a slash (/) then the PATH environment variable is searched for the executable.
on Windows systems the Win32 CreateProcess semantics is used. Briefly: if the filename does not contain a path, then the directory containing the parent executable is searched, followed by the current directory, then some standard locations, and finally the current PATH. An .exe extension is added if the filename does not already have an extension. For full details see the documentation for the Windows SearchPath API.
This is precisely what I would like to do but there doesn't seem to be any exposed functionality that does it. Am I just missing it, is there a more canonical/better way or do I have to dig through process
internals? The solution should be portable (Windows/Linux).
Looks like you want findExecutable
function from here.
Prelude System.Directory> findExecutable "gcc"
Just "/usr/bin/gcc"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With