如何从Haskell中的分叉进程读取数据?

如何从Haskell中的分叉进程读取数据?,haskell,process,system,Haskell,Process,System,谁能给我一个简短的例子,我调用一些系统命令,然后用haskell读出,例如打印 我知道我可以使用System.Cmd生成系统命令,如:nm、ls、mkdir等 但是我不需要只调用它们,我还需要读取它,并对读取的字符串进行一些操作,要使用的关键库是,它提供了 要调用命令并获取其输出,请执行以下操作: readProcess :: FilePath -- command to run -> [String] -- any arguments ->

谁能给我一个简短的例子,我调用一些系统命令,然后用haskell读出,例如打印

我知道我可以使用System.Cmd生成系统命令,如:nm、ls、mkdir等

但是我不需要只调用它们,我还需要读取它,并对读取的字符串进行一些操作,要使用的关键库是,它提供了

要调用命令并获取其输出,请执行以下操作:

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
具有您想要的功能,特别是
readProcess

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."
main=do
wcOut 10然后return()否则打印“那是一本小词典”
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."