Executing a system command in Haskell

扶醉桌前 提交于 2020-06-22 13:39:32

问题


How could I execute a system command such as cp somefile somedestination in Haskell?

Something like an os.Exec.


回答1:


The Haskell 98 standard provides:

System.system :: String
              -> IO GHC.IO.Exception.ExitCode

which executes a command.

The new System.Process library is more useful though, allowing for portable input/output redirection and so forth.




回答2:


I'm not a haskell buff, but this may be what you're looking for




回答3:


If you do this sort of thing a lot then it's worth having a look at http://hackage.haskell.org/package/HSH.




回答4:


module Main where

import System.Process

main = callCommand "cp somefile somedestination"

just works, but you may prefer other functions from the System.Process module.



来源:https://stackoverflow.com/questions/3470955/executing-a-system-command-in-haskell

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