Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pipe the stdout and stderr of a process to the same Handle?

How do I pipe the stdout and stderr of a process to the same Handle? On unix systems it's pretty easy, just use createPipe and pass the write end to runProcess as both stdout and stderr. On Windows it's harder:

  • Neither the unix-compat nor the Win32 package export a way to create pipes.

  • openTempFile (which could be use to simulate pipes) sets the wrong mode on the created Handle.

Edit: To give some more context: I want to run a process and have it write its stdout and stderr to the same Handle, in a cross-platform manner.

like image 410
tibbe Avatar asked Oct 29 '12 01:10

tibbe


1 Answers

You can use stuff from System.Process. In the CreateProcess definition there are

std_in       :: StdStream,               -- ^ How to determine stdin
std_out      :: StdStream,               -- ^ How to determine stdout
std_err      :: StdStream,               -- ^ How to determine stderr

and StdStream have this constructor:

data StdStream = UseHandle Handle

After that, pass the object you formed to the createProcess function to run your proc.

like image 69
arrowd Avatar answered Oct 18 '22 00:10

arrowd