popen2 + passwd

Donn Cave donn at u.washington.edu
Mon May 15 18:44:05 EDT 2000

Jp Calderone <exarkun at flashmail.com> wrote:
|  Can anyone tell me why this doesn't work?
|  import popen2
|  i, o = popen2.popen2('passwd bin')
|  pwd = '12345ASD'
|  o.write(pwd + '\n')
|  o.write(pwd + '\n')
|  i.close()
|  o.close()
|   Running it through the interpreter yields no output (as it should),
|  but the password for the bin user doesn't change to what I'd expect
|  it to (12345ASD), but to something else.

Most versions of the "passwd" program will try to turn off echo on
their input unit.  That's a tty device ioctl(), and a pipe device is
not valid for that.  When it fails, I would expect the program to abort.
I'd expect to see a password prompt, but not the second password prompt.

There's a special device, called a pseudo-tty, or pty, to use with
applications that need a terminal device.  Python's pty module can do
that for a few platforms, and there have been "expect" solutions.
The real Expect is a widely used Tcl application that uses a pty to
interact with an external application.

	Donn Cave, donn at u.washington.edu

More information about the Python-list mailing list