How to invoke bash or shell scripts from a haskell program?
Yes, it is possible. You can use process
package, which exports many useful functions. Simplest one is System.Cmd.system
, which can run some application in shell, yielding exit code.
More advanced features are provided too in the System.Process
module. With this module you can run process and communicate with it in many ways (input piping, exit codes, waiting for process to stop, modify its environment etc).
You can use System.Process
.
For example, executing seq 1 10
shell command:
> import System.Process
> readProcess "seq" ["1", "10"] ""
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
it :: String
> readProcessWithExitCode "seq" ["1", "10"] ""
(ExitSuccess,"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n","")
it :: (GHC.IO.Exception.ExitCode, String, String)
Turtle is pretty nice modern haskell library for this.
Of course. You can start by using system to invoke external processes.
More sophisticated piping and process control is available in a cross-platform way from the System.Process library.
Finally, you can consider porting your shell scripts to Haskell, via shell DSLs.