Calling an external command from a Haskell program
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, Salvador.
I think library module System, function system, may be what you want. (I've never used it myself.) There's a bit of discussion here: http://www.dcs.gla.ac.uk/mail-www/haskell/msg02441.html #g -- At 09:44 15/10/03 +0200, 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,
Salvador. _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
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 Regards -- Adrian Hey
Adrian Hey <ahey@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
Hi, Mikael Brockman wrote:
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.
Yes, in fact, this was the reason to send my first message. I already knew about 'system' in library System, but the Hugs installation says: -- Warning: the implementation of these functions in Hugs 98 is very weak. -- The functions themselves are best suited to uses in compiled programs, -- and not to use in an interpreter-based environment like Hugs. Thus, since I normally use Hugs rather than GHC I was afraid to have some problem (which one?) with it.
From Haskell's WiKi pages I learnt that something else was available for POSIX (which I do not use :-( ).
Anyway, I have implemented my utility by using system and it seems to run quite ok... Unfortunately I still do not know which is the weak point of these functions in Hugs... Best regards, Salvador.
I already knew about 'system' in library System, but the Hugs installation says:
-- Warning: the implementation of these functions in Hugs 98 is very weak. -- The functions themselves are best suited to uses in compiled programs, -- and not to use in an interpreter-based environment like Hugs.
This warning is (rather carelessly) applied to the entire module when, in fact, it only applies to getArgs and getProgName when used in an interpretive environment (i.e., hugs but not runhugs). The error message isa also a bit misleading since the problem lies not in the implementation but in choosing a sensible semantics for these functions when there is no ProgName and no Args. The function getEnv works fine in Hugs. The function system works fine in Hugs except on windows where DOS limitations cause the function to always return ExitSuccess. (ghc suffers from the same problem on Windows.) -- Alastair Reid www.haskell-consulting.com
participants (5)
-
Adrian Hey -
Alastair Reid -
Graham Klyne -
Mikael Brockman -
Salvador Lucas