getting the path to the executing program
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. -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
On Thu, Jan 08, 2004 at 09:06:44AM -0800, Hal Daume III wrote:
is there a function, related to getProgName, which returns the (absolute) path to the current program?
A non-portable Linux solution: System.Posix.readSymbolicLink "/proc/self/exe" Best regards, Tom -- .signature: Too many levels of symbolic links
On Thu, Jan 08, 2004 at 07:02:04PM +0100, Tomasz Zielonka wrote:
On Thu, Jan 08, 2004 at 09:06:44AM -0800, Hal Daume III wrote:
is there a function, related to getProgName, which returns the (absolute) path to the current program?
A non-portable Linux solution:
System.Posix.readSymbolicLink "/proc/self/exe"
A non-portable FreeBSD solution: System.Posix.readSymbolicLink "/proc/curproc/file" Best regards, Tom -- .signature: Too many levels of symbolic links
On Thursday 08 January 2004 18.06, Hal Daume III 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.
I don't know how to do this in a portable way, but on unix/linux you can use the standard trick of reading the symbolic link /proc/<process-id>/exe . For example: import System.Posix.Files (readSymbolicLink) import System.Posix.Process (getProcessID) main = do pid <- getProcessID path <- readSymbolicLink ("/proc/" ++ (show pid) ++ "/exe") putStrLn ("Absolute path of this program is " ++ path) PS. This doesn't work with interpreted code (Hugs, GHCi) in which case you get the path to the interpreter itself. Cheers Per
True. Replace "the" with "a" and "?" with ", if it exists?". On Thu, 8 Jan 2004, Lennart Augustsson wrote:
Hal Daume III wrote:
is there a function, related to getProgName, which returns the (absolute) path to the current program? Well, the absolute path name is not necessarily unique, nor is it guaranteed to exist. :)
-- Lennart
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
Hal Daume III <hdaume@ISI.EDU> writes:
True. Replace "the" with "a" and "?" with ", if it exists?".
On Thu, 8 Jan 2004, Lennart Augustsson wrote:
Hal Daume III wrote:
is there a function, related to getProgName, which returns the (absolute) path to the current program?
Well, the absolute path name is not necessarily unique, nor is it guaranteed to exist. :)
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&threadm=9201%40j... This is all you can get, I am afraid. Feri.
participants (5)
-
Ferenc Wagner -
Hal Daume III -
Lennart Augustsson -
Per Larsson -
Tomasz Zielonka