How to invoke bash or shell scripts from a haskell program?

前端 未结 4 2337
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 22:16

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.

4条回答
  •  不知归路
    2020-12-29 22:44

    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)
    

提交回复
热议问题