2011-04-29 2 views
2

누가 시스템 명령어를 호출하고 haskell로 읽을 수 있는지에 대한 짧은 예제를 제공 할 수 있습니다. 인쇄 해?하스켈에서 분기 된 프로세스에서 데이터를 읽는 방법?

내가 System.Cmd이 같은 시스템 명령을 만들기 위해 사용할 수 있다는 것을 알고 : MKDIR 등 나노, LS,

하지만 난 단지도 내가 몇 가지 작업을 그것을 읽고 만들 필요가 그들을 호출 할 필요가없는 읽은 문자열

답변

2

System.Process 원하는 기능이 있습니다

는 명령을 호출하고 출력으로 활용하려면 다음

readProcess 
     :: FilePath -- command to run 
     -> [String] -- any arguments 
     -> String   -- standard input 
     -> IO String -- stdout 

과 같이 :로 실행

import System.Process 

main = do 
    s <- readProcess "/bin/date" [] [] 
    putStrLn $ "The date is " ++ s 

을 .

main = do 
    wcOut <- readProcess "wc" ["/usr/share/dict"] [] 
    let numLines = read (head (words wcOut)) :: Int 
    if numLines > 10 then return() else print "That's a small dictionary." 
관련 문제