Hi, I am newbie in Haskell programing and need to launch a shell command through a Haskell code. In other programing languages like C or Java I know how carry out this task; for instance the code system("ls -l ") in C or exec("ls -l") in Java work fine and lists the working directory. I know that in interactive mode the Haskell command :! ls -l is similar, but ¿It is possible something like in Haskell non-interactive mode? Thaks in advance. Helptex23
On Tue, 2006-07-04 at 11:22 +0200, J. E. Palomar wrote:
Hi,
I am newbie in Haskell programing and need to launch a shell command through a Haskell code. In other programing languages like C or Java I know how carry out this task; for instance the code
system("ls -l ")
in C or
exec("ls -l")
in Java work fine and lists the working directory. I know that in interactive mode the Haskell command :! ls -l is similar, but ¿It is possible something like in Haskell non-interactive mode?
The function you're looking for is called 'system' and is in the System module. System.system :: String -> IO ExitCode it does just the same as the C and Java versions. BTW, one way you could have found this out is to search using hoogle: http://haskell.org/hoogle/ searching for 'system' gives the one we want as part of the search results http://haskell.org/hoogle/?q=system and links to the detailed documentation: http://haskell.org/ghc/docs/latest/html/libraries/base/System-Cmd.html#v %3Asystem Duncan
System.Cmd.rawSystem provides more portable interface than System.Cmd.system. The behaviour of System.Cmd.system depends on the installed system shell. rawSystem directly creates a new process without interaction with the shell. System.Process module provides even more advanced API. Cheers, Krasimir 2006/7/4, Duncan Coutts <duncan.coutts@worc.ox.ac.uk>:
On Tue, 2006-07-04 at 11:22 +0200, J. E. Palomar wrote:
Hi,
I am newbie in Haskell programing and need to launch a shell command through a Haskell code. In other programing languages like C or Java I know how carry out this task; for instance the code
system("ls -l ")
in C or
exec("ls -l")
in Java work fine and lists the working directory. I know that in interactive mode the Haskell command :! ls -l is similar, but ¿It is possible something like in Haskell non-interactive mode?
The function you're looking for is called 'system' and is in the System module.
System.system :: String -> IO ExitCode
it does just the same as the C and Java versions.
BTW, one way you could have found this out is to search using hoogle:
searching for 'system' gives the one we want as part of the search results
http://haskell.org/hoogle/?q=system
and links to the detailed documentation:
http://haskell.org/ghc/docs/latest/html/libraries/base/System-Cmd.html#v %3Asystem
Duncan
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
You had the solution in the topic of your post! Look at System.Cmd Or maybe you prefer to use System.Process The GHC documentation includes extensive docs about libraries: http://www.haskell.org/ghc/docs/latest/html/libraries/index.html Cheers Pepe On 7/4/06, J. E. Palomar <jepalomar23@ono.com> wrote:
Hi,
I am newbie in Haskell programing and need to launch a shell command through a Haskell code. In other programing languages like C or Java I know how carry out this task; for instance the code
system("ls -l ")
in C or
exec("ls -l")
in Java work fine and lists the working directory. I know that in interactive mode the Haskell command :! ls -l is similar, but ¿It is possible something like in Haskell non-interactive mode?
Thaks in advance.
Helptex23
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
On 04/07/06, J. E. Palomar <jepalomar23@ono.com> wrote:
lists the working directory.
Of course, for such a simple command, you'd be better off using System.Directory [1], but I guess you have more complicated applications in mind. [1]: http://haskell.org/ghc/docs/latest/html/libraries/base/System-Directory.html -- -David House, dmhouse@gmail.com
participants (5)
-
David House -
Duncan Coutts -
J. E. Palomar -
Krasimir Angelov -
Pepe Iborra