getting the path to the executing program

Hal Daume III hdaume at ISI.EDU
Thu Jan 8 09:27:28 EST 2004


Sadly, this doesn't seem to work:

9:26am albini:SVMseq/ cat Foo.hs
module Main where
import System.Environment
main = getEnv "_" >>= putStrLn

9:27am albini:SVMseq/ ghc Foo.hs -o foo
9:27am albini:SVMseq/ ./foo

Fail: does not exist
Action: getEnv
Reason: no environment variable
File: _



On Thu, 8 Jan 2004, Christopher Milton wrote:

> The environmental var "_" in $ENV{"_"} (pardon my Perlish) holds
> the full path name of the command currently executing (itself), at
> least on RedHat Linux and HP-UX, so you should be able to use
> getEnv... I think... 
> 
> --- Hal Daume III <hdaume at ISI.EDU> wrote:
> > is there a function, related to getProgName, which returns the (absolute) 
> > path to the current program?
> > 
> > basically, i want to be able to read a file which i know will be in the 
> > same directory as the current program, but not necessarily in the same 
> > directory that we're running it from.
> 
> 
> =====
> Christopher Milton
> cmiltonperl at yahoo.com
> 

-- 
 Hal Daume III                                   | hdaume at isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume



More information about the Haskell mailing list