[Haskell-cafe] Closest analog to popen()

Donn Cave donn at drizzle.com
Tue Apr 12 16:47:29 EDT 2005

On Tue, 12 Apr 2005, Dimitry Golubovsky wrote:
> Does there exist any analog of popen in the standard Haskell libraries?
> I need to execute an external program (not a Haskell funciton) - maybe
> in a shell, being able to feed something to its stdin, and finally
> catch the exit code. Does there exist a way to do this without dealing
> with multithreading, writing my own ffi and other stuff?
> Something like rawSystem, but acting asynchronously (returning a
> writeable pipe handle, and a process ID), and later I would use
> getProcessStatus to catch the exit code.
> PS I have found
> http://community.moertel.com/ss/space/Tom's+Haskell+code/POpen.hs
> so far, but it does not seem to be part of the standard library.

True, but it looks like it might show a way to do this without dealing
with multithreading, writing your own ffi and other stuff.  It sounds
like his popenRaw would work for your application.  As you probably
know, you will need to at least flush output and possibly close the
pipe in order to get all output from the child process, because of
buffering in the respective processes.

Incidentally, if it had been up to me, System.Posix.Process executeFile 
would have taken the entire argv list [0..n].   [1..n] seems like a
gratuitous abridgement to the underlying functionality.

	Donn Cave, donn at drizzle.com

More information about the Haskell-Cafe mailing list