
Am Samstag, 7. Juli 2007 11:27 schrieb Ketil Malde:
I notice that when I try to execute a non-existing command with runInteractiveProcess, nasty things happen when I close the input. To be exact, the whole program terminates. Is this the intended behavior, and if so, what is the correct way to work around it?
Loading package base ... linking ... done. Prelude> :m + System.IO Prelude System.IO> :m + System.Process Prelude System.IO System.Process> (i,o,e,p) <- runInteractiveCommand "asdf" Prelude System.IO System.Process> hPutStr i "foo" Prelude System.IO System.Process> hClose i
If you look at the exit status of ghci, you'll see that it was terminated by SIGPIPE. This happens because you're trying to write to a pipe that has no reader on the other end (because "asdf" doesn't exist/run). It happens in hClose because i is buffered, so the hPutStr doesn't actually send anything. hClose tries to flush the buffer, which triggers the SIGPIPE. The solution is to install a signal handler for SIGPIPE, even if it just ignores the signal; something like: installHandler sigPIPE Ignore Nothing This should make write() fail with EPIPE, which should be turned into an IO exception by hClose (ok, so you still need to catch that but at least it doesn't kill your whole program). HTH, Lukas