I'm writing some shell scripts with haskell, which I'm running in gitbash, but there are a few other existing scripts I'd like to be able to use from those scripts.

For example, I'd like to run maven goals or do a git pull, but without having to integrate specifically with those tools.

Is there a way to do this?

share|improve this question
up vote 15 down vote accepted

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)
share|improve this answer

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).

share|improve this answer

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.

share|improve this answer

Turtle is pretty nice modern haskell library for this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.