2017-07-18 88 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