从createProcess外部获得的句柄中读取 [英] Reading from a handle obtained outside createProcess
问题描述
我试图创建一个进程,并通过我在 createProcess
函数之外提供的句柄与它进行通信:
stdOutH < - openFile(logDir >stdout.log)ReadWriteMode
hSetBuffering stdOutH LineBuffering
(_,_,_ ,ph)< - createProcess
(procsomeproc[]){std_out = UseHandle stdOutH
,std_err = UseHandle stdErrH
}
line< - hGetLine stdOutH
putStrLn $Got++行
我不明白为什么在创建的进程正在运行时关闭句柄。如果我使用 那么,有没有一种方法可以使用 请注意,通过 文档建议使用 I'm trying to create a process, and communicate with it via a handle that I provide outside the The hGetLine: illegal operation (handle is closed) What I don't understand is why the handle is closed while the created process is running. This works if I use So, is there a way to use This behavior of Note that Handles provided for std_in, std_out, or std_err via the
UseHandle constructor will be closed by calling this function. Documentation suggests to use 这篇关于从createProcess外部获得的句柄中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!someproc
进程向标准输出吐出一行,我想从产生它的进程读取它。然而,如果我尝试这样做,我会得到以下错误:
$ b
CreatePipe
而不是 UseHandle
,这是有效的,问题是我只想读第一行。但是这样做需要继续读取管道,否则在someproc
。
system.process
来通过 stdOutH
在上面描述的方式? createProcess
的这种行为是记录在案:
UseHandle构造函数为std_in,std_out或std_err提供的句柄将通过调用此函数来关闭。
createProcess _
函数。createProcess
function:stdOutH <- openFile (logDir </> "stdout.log") ReadWriteMode
hSetBuffering stdOutH LineBuffering
(_, _, _, ph) <- createProcess $
(proc "someproc" []) { std_out = UseHandle stdOutH
, std_err = UseHandle stdErrH
}
line <- hGetLine stdOutH
putStrLn $ "Got " ++ line
"someproc"
process spits a line out to the standard output, and I want to read it from the process that spawned it. However if I try to do this I get the following error:CreatePipe
instead of UseHandle
, the problem is that I only want to read the first line. But doing this requires to keep on reading from the pipe, otherwise it gets full after a certain amount of output by "someproc"
.system.process
to communicate two processes via stdOutH
in the way described above?createProcess
is documented:
createProcess_
function instead.