Proposal: Add getFullProgName
sol at typeful.net
Wed Jun 13 10:38:50 CEST 2012
> 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.
> 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 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
For reference, there are several packages on Hackage that try to solve
this in some way .
More information about the Libraries