Haskell 管道化两个子流程时的快速行为
我有以下代码的活泼行为Haskell 管道化两个子流程时的快速行为,haskell,process,Haskell,Process,我有以下代码的活泼行为 {-# LANGUAGE OverloadedStrings #-} module Main where import Control.Concurrent (threadDelay) import qualified Control.Concurrent.Async as Async import qualified System.Process.Typed as Proc import qualified System.Process
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Concurrent (threadDelay)
import qualified Control.Concurrent.Async as Async
import qualified System.Process.Typed as Proc
import qualified System.Process as P
import qualified GHC.IO.Handle as H
main :: IO ()
main = do
print "starting"
(readEnd, writeEnd) <- P.createPipe
let p1 = Proc.setStdout (Proc.useHandleClose writeEnd) "echo -n 'foo'"
let p2 = Proc.setStdin (Proc.useHandleClose readEnd) "base64 -"
Async.concurrently
(threadDelay 1000 *> Proc.runProcess_ p2) -- with the delay, it works
-- (Proc.runProcess_ p2) -- that line will make the program hang forever
(Proc.runProcess_ p1)
print "done"
System.Process.Typed
有一个createPipe
方法,该方法返回一个streamspec,也许您应该使用它而不是System.Process
的版本。有一个例子与您在of类型化过程中所做的工作非常接近。它似乎只是关于父级和子级之间的通信,但并不直接处理子级之间的通信。
Proc.withProcess_ "echo -n foo" $ \r1 -> do
let p2 = Proc.setStdin (Proc.getStdout r1) "base64"
• Couldn't match expected type ‘Proc.StreamSpec
'Proc.STInput stdin0’
with actual type ‘()’
• In the first argument of ‘Proc.setStdin’, namely
‘(Proc.getStdout r1)’
In the expression: Proc.setStdin (Proc.getStdout r1) "base64"