[Haskell-cafe] Re: HSH and IO ()

John Goerzen jgoerzen at complete.org
Sat Jun 13 22:53:48 EDT 2009

Dimitry Golubovsky wrote:

> I'll try to write a wrapper for a forked process inside a Channel ->
> IO Channel typed function.

Your best bet would be to start with these instances in HSH.Command:

instance ShellCommand (String, [String]) where
instance ShellCommand String where

and the implementation of genericCommand, which they both call.

It is really not that difficult of an implementation, and as of GHC
6.10, no longer even requires the specialized POSIX items.

The reason I have two bodies for genericCommand is that if the input
channel is a Handle, I can pass it directly as stdin to the child
process; otherwise, it is necessary to use chanToHandle to zap it over
to stdin.

Now, with what you're trying to do, you will probably not be able to get
away without using the POSIX stuff though, since you have to dup2()

I still recommend splitting this into multiple executables.  With your
approach, the stdin and stdout of your main executable will be messed up
forever.  This can and does lead to unforseen consequences.

-- John

More information about the Haskell-Cafe mailing list