[Haskell-cafe] trying to understand runProcess handles
Matthias Fischmann
fis at wiwi.hu-berlin.de
Thu Mar 2 12:43:07 EST 2006
hi there,
I am running some unix command. I just realized there is
runInteractiveProcess in System.Process, so my problem is solved in
practice:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
showPlot :: String -> IO (Handle, Handle, Handle, ProcessHandle)
showPlot file = runInteractiveProcess executable arguments wd env
where
executable = "/usr/bin/gnuplot"
arguments = ["-geometry", "-19+3", file, "-"]
wd = Nothing
env = Nothing
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
But first I tried to create the handles myself with createPipe from
System.Posix.IO, and I failed for a reasons that I have no clue how to
learn to understand. This is what the code looked like:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
showPlot :: String -> IO (ProcessHandle, Handle, Handle, Handle)
showPlot file = do
(stdinR, stdinW) <- createPipeHandles
(stdoutR, stdoutW) <- createPipeHandles
(stderrR, stderrW) <- createPipeHandles
h <- runProcess
executable arguments wd env
(Just stdinR) (Just stdoutW) (Just stderr W)
return (h, stdinW, stdoutR, stderrR)
where
executable = "/usr/bin/gnuplot"
arguments = ["-geometry", "-19+3", file, "-"]
wd = Nothing
env = Nothing
createPipeHandles :: IO (Handle, Handle)
createPipeHandles = do
(fR, fW) <- createPipe
hR <- fdToHandle fR
hW <- fdToHandle fW
return (hR, hW)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The problem is that gnuplot terminates right away after it tries to
read from stdin (I can see the shadow of a window appear and vanish
immediately). I tried setFdOption, with no effect. Is this because
the handles passed to runProcess are closed in the parent process, and
therefore the pipe is teared down and useless?
I don't think so: If I run 'find /' instead of gnuplot, the process
happily starts and I can hGetLine from stdout.
If you have any clue I'd love to learn. Anyway, as I said, it's
really better to simply use runInteractiveProcess in this simple case.
thanks,
Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060302/5b053b45/attachment.bin
More information about the Haskell-Cafe
mailing list