0
如何扩展“Running processes concurrently”以包含stdin和stdout?与stdin同时运行进程stdout
例如,让我们说,我的(Windows)中的命令输出10 stdout和我要检查所有进程的输出是正确的:
let cmds = replicate 100 "echo 10"
我应该怎么写Haskell的计划?
如何扩展“Running processes concurrently”以包含stdin和stdout?与stdin同时运行进程stdout
例如,让我们说,我的(Windows)中的命令输出10 stdout和我要检查所有进程的输出是正确的:
let cmds = replicate 100 "echo 10"
我应该怎么写Haskell的计划?
import Control.Concurrent.Async
import System.IO
import System.Process
你链接的网站上的代码使用runCommand
;使您能够访问流的等价物是runInteractiveCommand
。然后您可以使用hGetContents
从流中读取。
-- | Run @echo [email protected] 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")
然后我们可以使用replicateConcurrently
从async
包来运行它,同时100次,fmap (all id)
对结果采取一切结果的布尔和。
-- | Run 'testOne' 100 times concurrently, return whether all tests succeeded.
testMany :: IO Bool
testMany =
all id <$> replicateConcurrently 100 testOne