I'm trying to run the elm-reactor project, which is written in Haskell. It fails because it's trying to proc out to the elm
command like this:
createProcess (proc "elm" $ args fileName)
My elm executable is sitting in ~/.cabal/bin, which is in my PATH.
The System.Process.proc
command searches the $PATH for its command argument, but it doesn't do tilde (~) expansion, so it doesn't find elm.
System.Process.shell
has the opposite problem. It does tilde expansion, but it doesn't search the $PATH, apparently.
From the source of the System.Process command, it looks like most everything rests on a foreign ccall to "runInteractiveProcess", which I assume is doing whatever $PATH searching is being done. I don't know where the source for runInteractiveProcess would be, and my C is about 15 years worth of rusty.
I can work around this issue by
a) adding the fully-expanded cabal/bin path to my PATH or
b) symlinking an elm
from the working directory to its location in cabal/bin.
However, I'd like to offer a suggested fix to the elm project, to save future adopters the trouble I've gone through. Is there a System.Process
call that they should be making here that I haven't tried? Or is there a different method they should be using? I suppose at worst they could getEnv
for the PATH and HOME, and implement their own file search using that before calling proc - but that breaks cross-platform compatibility. Any other suggestions?
Try using shell
instead of proc
, i.e.:
createProcess (shell "elm")
This should invoke elm
via a shell, which hopefully will interpret tildes in $PATH
as desired.
Update: Here is the experiment I performed to test what shell
does...
Compile the following program (I called it run-foofoo
):
import System.Process
main = do (,,_,h) <- createProcess $ shell "foofoo" ec <- waitForProcess h print ec
Create a new directory ~/new-bin
and place the following perl script there as the file foofoo
:
#!/usr/bin/perl
print "Got here and PATH is $ENV{PATH}\n";
Run: chmod a+rx ~/new-bin/foofoo
Test with:
PATH="/bin:/usr/bin:/sbin" ./run-foofoo # should fail
PATH="$HOME/new-bin:/bin:/usr/bin:/sbin" ./run-foofoo # should succeed
PATH="~/new-bin:/bin:/usr/bin:/sbin" ./run-foofoo # ???
On my OSX system, the third test reports:
Got here and PATH is ~/new-bin:/bin:/usr/bin:/sbin
ExitSuccess
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句