How can I do a tilde expansion AND $ PATH search in Haskell?

I am trying to run an el reactor project which is written in Haskell. It fails because it tries to execute the command elm

like this:

createProcess (proc "elm" $ args fileName)

      

the elm executable sits in ~ / .cabal / bin which is in my PATH.

The command System.Process.proc

looks for $ PATH for its command argument, but does not expand the tilde (~), so it does not find elm.

System.Process.shell

has the opposite task. It expands the tilde, but doesn't seem to look up $ PATH.

From the source of the System.Process command, it looks like most of them rely on someone else's ccall on "runInteractiveProcess", which I believe does everything the $ PATH lookup does. I don't know where the source for runInteractiveProcess would be, and my C is rusty for about 15 years.

I can get around this problem with

a) adding the fully expanded cabal / bin path to my PATH, or

b) symlinking elm

from the working directory to its location in cabal / bin.

However, I would like to propose a suggested solution for the elm project in order to spare future followers of the problems that I went through. Is there a call System.Process

they should be making here that I haven't tried? Or is there another method they should use? I suppose that in the worst case they could be getEnv

for PATH and HOME and implement their own file search using this before the proc call, but this breaks compatibility between platforms. Any other suggestions?

+3


source to share


1 answer


Try using shell

instead proc

, that is:

createProcess (shell "elm")

      

This should be called elm

through a shell, which will hopefully interpret tildes in $PATH

at will.

Update: here is an experiment I ran to test what does shell

...

  • Compile the following program (I named 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 file in the file foofoo

    :

    #! / Usr / bin / perl

    print "Obtained here and PATH is $ ENV {PATH} \ n";

  • Run: chmod a+rx ~/new-bin/foofoo



Test using

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 report:

Got here and PATH is ~/new-bin:/bin:/usr/bin:/sbin
ExitSuccess

      

+2


source







All Articles