
Hi, 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. -- Dimitry Golubovsky Anywhere on the Web

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@drizzle.com

On 2005-04-12, Dimitry Golubovsky
Does there exist any analog of popen in the standard Haskell libraries?
Dmitry, I have one in MissingH, and it's written in pure Haskell. Reference at http://quux.org/devel/missingh/html/MissingH.Cmd.html, code at http://quux.org/devel/missingh. If you choose to not use that code, and instead write your own, just know that popen() can be implemented in terms of pipe(), dup(), and fork() in C -- or createPipe, dupTo, and forkProcess in Haskell. Take care to handle SIGCHLD properly -- or, just use my module :-) -- John

Dimitry Golubovsky writes:
Does there exist any analog of popen in the standard Haskell libraries?
Maybe System.Process.runInteractiveCommand is what you need? http://haskell.org/ghc/docs/latest/html/libraries/base/System.Process.html Peter

Peter Simons wrote:
Dimitry Golubovsky writes:
Does there exist any analog of popen in the standard Haskell libraries?
Maybe System.Process.runInteractiveCommand is what you need?
http://haskell.org/ghc/docs/latest/html/libraries/base/System.Process.html
Is this available only in 6.4? In 6.2.2 I've got only System.Posix.Process, and this is just binding to Unix functions dealing with processes. Thanks for pointing me out. Dimitry Golubovsky Middletown, CT
participants (5)
-
Dimitry Golubovsky
-
Dimitry Golubovsky
-
Donn Cave
-
John Goerzen
-
Peter Simons