如何检查bash命令是否已成功执行

时间:2012-02-13 17:34:19

标签: haskell

我正在尝试在Haskell中创建一个小程序。我需要做的是检查Haskell解释器是否已成功执行bash命令。让我们说“伪代码”:

  $import System

  $if( system "ls" ) has been succesfully run 
  $then doStuff

你会如何在Haskell中编写这段代码?

1 个答案:

答案 0 :(得分:7)

你可以这样做:

import System

main = do
  result <- system "ls"
  case result of
    ExitSuccess ->
      putStrLn "Ran successfully"
    ExitFailure code ->
      putStrLn $ "Failed with exit code " ++ show code