Calling an external command from a Haskell program
Mikael Brockman
phubuh at phubuh.org
Tue Oct 21 09:24:55 EDT 2003
Adrian Hey <ahey at iee.org> writes:
> On Wednesday 15 Oct 2003 8:44 am, Salvador Lucas wrote:
> > Dear all,
> >
> > I think this question is not new, but I am not able to
> > find the answer. How to proceed to execute an external
> > Linux command (e.g., 'ls') from a Haskell program?
> >
> > Thanks in advance,
>
> You can use..
> system :: String -> IO ExitCode
> in library module System.Cmd
>
If you want access to its I/O streams as well, you can use
Posix.popen, which is not standard Haskell 98, I think, but it's in
GHC.
-- Looks up a word by passing it to `cmafihe'.
cmafihe :: String -> IO String
cmafihe word = popen cmafihePath [] (Just word) >>= return . fst3
where cmafihePath = "/usr/local/bin/cmafihe"
fst3 (a, b, c) = a
More information about the Haskell
mailing list