Rog*_*062 3 haskell createprocess handle smt
当我使用Haskell createProcess时,我需要fork之前好像我在c中使用exec吗?
从我已经看到的示例和我已经尝试的我不认为我做但如果我从输出句柄读取一旦我得到预期的结果但如果我尝试阅读两次它甚至不读一次.
例如:
beginProcess与createProcess相同,z3是从stdin读取并写入stdout的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
Run Code Online (Sandbox Code Playgroud)
如果我执行一个我得到预期的结果,但如果我这样做都没有任何反应.我在读取或写错了句柄吗?
感谢您提供任何帮助.
我有一种预感,你"正在遭受缓冲".
请注意,您没有向z3进程发出任何换行符.此外,z3可能不会在每个命令后刷新其输出.
与终端程序交互的最佳方式是通过伪tty.以下是对此类设置如何工作的解释:http://rachid.koucha.free.fr/tech_corner/pty_pdip.html