[Haskell-beginners] merge two handles

Antoine Latter aslatter at gmail.com
Mon Jun 13 22:14:26 CEST 2011


On Mon, Jun 13, 2011 at 1:14 PM, Manfred Lotz <manfred.lotz at arcor.de> wrote:
> On Mon, 13 Jun 2011 12:51:02 -0500
> Antoine Latter <aslatter at gmail.com> wrote:
>
>> On Mon, Jun 13, 2011 at 12:35 PM, Manfred Lotz
>> <manfred.lotz at arcor.de> wrote:
>> > Hi all,
>> > I have two handles where I get stdout resp. stderr from a command
>> > output.
>> >
>> >
>> > Is it possible to merge those two handles so that I get a new input
>> > handle in a way that data can be read from the new handle whenever
>> > it is available from either of the two original handles?
>> >
>> >
>>
>> Does what you're doing strictly need to be a handle?
>>
>> One thing you could try is is using an IO Channel:
>> http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Concurrent-Chan.html
>>
>
> Hmm, not quite sure. I was asking about handles because I use:
>
> (_ ,Just hout ,Just herr ,p) <- createProcess (proc cmd parms) {
>    std_out = CreatePipe,
>    std_err = CreatePipe
>  }
>
>
> which gives me handles to deal with.
>

You could create the pipe yourself, and then call 'createProcess' with
'UseHandle' instead, passing the same handle to both std_out and
std_error.

On a unix-y system you can do this with the functions in System.Posix.IO.

I'm not sure what you would do on windows. This might be a good
question to open up to a wider audience on the haskell-cafe mailing
list.

Antoine



More information about the Beginners mailing list