Interfacing with terminal programs
drifty at bigfoot.com
Mon May 14 04:15:41 CEST 2001
For instance, a wrote a small Python script that basically prompted
for info, printed some text, and then ended. When I tried using
popen2 on it I couldn't read the prompt. It always hung. Now a post
said that I should flush it first. I vaguely remember trying that and
still having a problem, but I will give that a go just to
I have a feeling that using a pty is going to be my best bet. If that
doesn't work I am going to try Mr. Laird's suggestion of using Expect
to see if that will do the job. Thanks for the help.
On 13 May 2001 03:02:39 GMT, Donn Cave <donn at oz.net> wrote:
>I'm not sure what you mean by that. The usual problem, when you
>run a program on a pair of pipes, is that the program's output is
>block buffered when the device is a pipe, and the output you're
>waiting to read is still in that buffer. A prompt is a bit less
>likely to have this problem, because in the normal tty context
>where output is line buffered, you have to explicitly flush output
>from the buffer to get a prompt. Ptys solve the buffering problem.
>The stderr stream is usually unbuffered, so it will come right out -
>but not to the output pipe, if they prompt on stderr.
>Anyway, the other problem that will come up with a password prompt
>is the tty ioctl that turns off echo. That will fail on the pipe,
>which doesn't support tty ioctls. The passwd program should abort
>at that point. Ptys solve this problem too.
>| Any suggestions? This has to run on Solaris, so using something like
>| pty is obviously iffy.
>I think pty is the only thing that can work. Look for posix.openpty.
>You'll have to fiddle around with it, ptys are odd devices that are
>a little more trouble to work with.
> Donn Cave, donn at oz.net
More information about the Python-list