Accpeting command-line arguments in GHC/Hugs
How can I read the command-line arguments passed to the program. For instance, if I run my compiled program by typing "./foo hello -o file.txt", I wish to access the list ["hello", "-o", "file.txt"] somehow. TIA, Shlomi Fish ---------------------------------------------------------------------- Shlomi Fish shlomif@vipe.technion.ac.il Home Page: http://t2.technion.ac.il/~shlomif/ Home E-mail: shlomif@techie.com The prefix "God Said" has the extraordinary logical property of converting any statement that follows it into a true one.
Shlomi Fish wrote:
How can I read the command-line arguments passed to the program. For instance, if I run my compiled program by typing "./foo hello -o file.txt", I wish to access the list ["hello", "-o", "file.txt"] somehow.
module Main (main) where import System
main = getArgs >>= \args -> hugsMain args hugsMain :: [String] -> IO () hugsMain = print
ghc Main.lhs a.out foo bar --help ["foo","bar","--help"] Sengan
Shlomi Fish wrote:
How can I read the command-line arguments passed to the program. [...]
As already pointed out, System.getArgs is the basically the way to go. If you want to use the list returned by it comfortably, see: http://www.haskell.org/ghc/docs/latest/set/sec-util.html#SEC-GETOPT Cheers, Sven
participants (3)
-
Sengan -
Shlomi Fish -
Sven Panne