
getProgName is only useful in case you want to print the program name to the screen. You cannot actually use it to do anything interesting programmatically (like execv:ing the program.) I suggest we add getFullProgName which does the sensible thing of returning argv[0]. Here's an implementation:
getFullProgName :: IO String getFullProgName = alloca $ \ p_argc -> alloca $ \ p_argv -> do getFullProgArgv p_argc p_argv peek p_argv >>= peek >>= peekCString
foreign import ccall unsafe "getFullProgArgv" getFullProgArgv :: Ptr CInt -> Ptr (Ptr CString) -> IO ()
Discussion deadline: 2 weeks
This has bothered me for some time, so I really think we should do something about it. But I also think that argv[0] is only sane for compiled programs. If you run it with `runhaskell` or from `ghci` it will give you the path to ghc, which is not what I'd expect (from a users point of view). In analogous to getProgName I'd suggest to: * Return the full path to the script for `runhaskell` * Return "<interactive>" when run from GHCi Or we could make it explicit: getFullProgName :: IO ExecutablePath data ExecutablePath = Binary FilePath | Script FilePath | Interactive For reference, there are several packages on Hackage that try to solve this in some way [1][2][3]. Cheers, Simon [1] http://hackage.haskell.org/package/FindBin [2] http://hackage.haskell.org/package/executable-path [3] http://hackage.haskell.org/package/system-argv0