Haskell 与stdin、stdout并发运行进程

Haskell 与stdin、stdout并发运行进程,haskell,stdout,stdin,Haskell,Stdout,Stdin,如何扩展“”以包括标准输入和标准输出 例如,假设我的(Windows)命令在stdout上输出10,我想检查所有进程的输出是否正确: let cmds = replicate 100 "echo 10" 我应该如何编写Haskell程序 import Control.Concurrent.Async import System.IO import System.Process 您链接的网站上使用的代码;让您能够访问流的等价物是。然后可以使用从流中读取 -- | Run @echo 10@ a

如何扩展“”以包括标准输入和标准输出

例如,假设我的(Windows)命令在stdout上输出10,我想检查所有进程的输出是否正确:

let cmds = replicate 100 "echo 10"
我应该如何编写Haskell程序

import Control.Concurrent.Async
import System.IO
import System.Process
您链接的网站上使用的代码;让您能够访问流的等价物是。然后可以使用从流中读取

-- | Run @echo 10@ and tests whether the output is what we expect.
testOne :: IO Bool
testOne =
  runInteractiveCommand "echo 10" >>= \(_stdin, stdout, _stderr, _proc) ->
  hGetContents stdout >>= \out ->
  return (out == "10\n")
然后我们可以从
async
包中同时运行它100次,并对结果执行
fmap(all id)
以获取所有结果的布尔and

-- | Run 'testOne' 100 times concurrently, return whether all tests succeeded.
testMany :: IO Bool
testMany =
  all id <$> replicateConcurrently 100 testOne
——|同时运行“testOne”100次,返回是否所有测试都成功。
testMany::IO Bool
testMany=
所有id复制100 testOne