Comment detail

指定コマンドを別プロセスで起動 (Nested Flatten)

System.Processモジュールの runInteractiveCommand を使用しています。

同モジュールの waitForProcess は System.Exit モジュールの ExitCode型のIOを返します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import IO
import System.Process
import System.Exit

run :: String -> IO ()
run cmd = do (ih, oh, eh, ph) <- runInteractiveCommand cmd
             putStrLn =<< hGetContents oh
             status <- waitForProcess ph
             case status of
               ExitSuccess -> putStrLn $ cmd ++ " ok"
               ExitFailure code -> putStr "error: " >> print code

main :: IO ()
main = run "ls -la"

Index

Feed

Other

Link

Pathtraq

loading...