2017-07-18 34 views

回答

1
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") 

然后我们可以使用replicateConcurrentlyasync包来运行它,同时100次,fmap (all id)对结果采取一切结果的布尔

-- | Run 'testOne' 100 times concurrently, return whether all tests succeeded. 
testMany :: IO Bool 
testMany = 
    all id <$> replicateConcurrently 100 testOne 
相关问题