
Hi all, Is there a Haskell-Expect module? Something that would allow me to control an external Unix program via its stdin/stdout/stderr? Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- Seen on comp.lang.c : klaushuot : C rocks the world. Plain and simple. It's the ultimate solution, period. user923005 : Every tool should be a screwdriver. You can hammer with it, if you pound hard enough. You can pry with it -- just like a crowbar. Or, perhaps, there are room for other tools in the bag.

Hi Erik,
Is there a Haskell-Expect module? Something that would allow me to control an external Unix program via its stdin/stdout/stderr?
System.Process does what you want, I think: http://hackage.haskell.org/packages/archive/process/1.0.1.1/doc/html/System-... Thanks Neil

Quoth Neil Mitchell
Is there a Haskell-Expect module? Something that would allow me to control an external Unix program via its stdin/stdout/stderr?
System.Process does what you want, I think:
It might not. Expect uses pseudottys (cf. openpty()), and select(). System.Process supports what you might think of as the "naive" model, using pipes for the I/O device and making some simplifying assumptions about the behavior of the external program. It's more portable and works for many common cases, at least the popen() and system() usages that probably account for 98 percent of process invocations. But once you need output from a process _before_ it exits, you will encounter the problem with pipes: output to a pipe is normally block buffered, so it doesn't reliably get to the pipe on time. The C I/O library treats a pty device like a tty and line buffers output. (But unfortunately, a pty device is not just a pipe with that single property - I wouldn't replace pipes with ptys just as a matter of course, because depending on the OS they may do things like discard date on overflow, or they may be a severely limited system resource.) select() also helps with another potential problem, when the same process is writing to two or more pipes, which are fixed size devices. In GHC, I suppose the potential deadlock might similarly be avoided using threads. I don't know if GHC supports openpty() - having a little trouble getting data from its web site this morning. But of course there's more to Expect than just the raw system calls. Donn

Donn Cave wrote:
Quoth Neil Mitchell
: Is there a Haskell-Expect module? Something that would allow me to control an external Unix program via its stdin/stdout/stderr?
System.Process does what you want, I think:
It might not. Expect uses pseudottys (cf. openpty()), and select().
Yep, I definitely need the pty as the program I need to run asks for a password. Pipes won't work. Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "The earth is degenerating these days. Bribery and corruption abound. Children no longer mind parents ...and it is evident that the end of the world is approaching fast." -- Assyrian Tablet Engraved in 2800 B.C.

On 2009 Jan 19, at 3:47, Neil Mitchell wrote:
Is there a Haskell-Expect module? Something that would allow me to control an external Unix program via its stdin/stdout/stderr?
System.Process does what you want, I think:
http://hackage.haskell.org/packages/archive/process/1.0.1.1/doc/html/System-...
I don't see any pty stuff in there offhand. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (4)
-
Brandon S. Allbery KF8NH
-
Donn Cave
-
Erik de Castro Lopo
-
Neil Mitchell