Is it possible to invoke bash or shell scripts from a haskell program?

牧云@^-^@ 提交于 2019-12-03 04:54:06
ДМИТРИЙ МАЛИКОВ

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)

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

Don Stewart

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.

jhickner

Turtle is pretty nice modern haskell library for this.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!