[Haskell-cafe] How to get a file path to the program invoked?

scooter.phd at gmail.com scooter.phd at gmail.com
Mon Dec 5 03:32:30 CET 2011


It's not a poor practice at all. Example: gcc, which uses the executable's  
path as the base directory from which other files are located. MacOS also  
does something similar.

-----Original message-----
From: Paul R <paul.r.ml at gmail.com>
To: dokondr <dokondr at gmail.com>
Cc: Simon Hengel <simon.hengel at wiktory.org>, haskell-cafe  
<haskell-cafe at haskell.org>
Sent: Sun, Dec 4, 2011 15:26:28 PST
Subject: Re: [Haskell-cafe] How to get a file path to the program invoked?

dokondr> On the contrary, standard shell variable $0 - contains a full
dokondr> path to the program location in the directory structure, no
dokondr> matter from what directory the program was called.

I don't think the comparison makes sense, as shell script invocation and
executable run are very different mechanisms. Whenever you invoke
a shell script, what really happens is that a program in your path (sh,
bash ...) gets started with an argument that is the path to the script
to load (your script actually). In this situation, you understand that
it is easy to provide the path to the script (the $0) : it is just the
file that the interpreter is loading.

I don't know if it is possible at all to get this information in the
context of binary execution. And I'm not sure it is a good practice
anyway :)

-- 
  Paul

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111204/9c016972/attachment.htm>


More information about the Haskell-Cafe mailing list