【发布时间】:2014-01-28 19:40:12
【问题描述】:
当我使用 Haskell createProcess 时,是否需要像在 c 中使用 exec 一样进行 fork?
从我所看到的示例中,对于我所尝试的,我认为我没有这样做,但是如果我从输出句柄中读取,一旦我得到预期的结果,但是如果我尝试读取两次,它甚至不会读取一次.
例如:
beginProcess 与 createProcess 相同,z3 是一个从标准输入读取并写入标准输出的 smt 求解器。
execute :: Process -> String -> IO String
execute (Just std_in, Just std_out,_,_) cmd = do
hPutStr std_in cmd
hFlush std_in
hGetLine std_out
main :: IO()
main = do
proc <- beginProcess "z3" ["-smt2","-in"]
execute proc "(set-option :print-success true)" >>= print
execute proc "(set-option :print-success true)" >>= print
如果我执行一次,我会得到预期的结果,但如果我同时执行两次,则什么都不会发生。 我读错了还是写错了句柄?
感谢您提供的任何帮助。
【问题讨论】:
-
请出示您的进口商品。特别是
beginProcess是什么?我在 hoogle 或 hayoo 上找不到。 -
process库非常依赖于系统,因此您应该包括您正在使用的平台。
标签: haskell handle createprocess smt