2017-07-18 5 views
0

"Running processes concurrently"にstdinとstdoutを含めるにはどうしたらよいですか?例えばstdinとstdoutを同時に実行する

、のは私(Windowsの場合)コマンドの出力を標準出力に10、と私はすべてのプロセスの出力が正しいことを確認したいとしましょう:

let cmds = replicate 100 "echo 10" 

がどのように私はHaskellのプログラムを書く必要がありますか?

答えて

1

リンクしたウェブサイトのコードは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") 

その後、我々はすべての結果のブールを取るために、結果の上にそれを実行するためにasyncパッケージから100同時に回、およびfmap (all id)replicateConcurrentlyを使用することができます。

-- | Run 'testOne' 100 times concurrently, return whether all tests succeeded. 
testMany :: IO Bool 
testMany = 
    all id <$> replicateConcurrently 100 testOne 
関連する問題