still trying to pass strings to the OS

Bart Nessux bart_nessux at hotmail.com
Mon Feb 23 10:15:28 EST 2004


I posted on this topic a few days ago, got a tip to use popen to 
redirect stdin. Here's where I'm at now:

import popen2
r,w,e = popen2.popen3("/usr/bin/passwd")
print r.readline()
w.write("password")
w.flush()

When this is ran, the shell responds with "New password:" at the console 
and then nothing happens. I can key in the password and then confirm it 
manually after which "print r.readline()" does its thing by printing out 
"Changing password for user." Note that when the command is ran from the 
shell manually "Changing password for user." is the first thing printed 
to the console. So, here's my questions:

1. Why does my readline come last?
2. Also, when I do more than one readline, I get nothing, why is this?
    I should be able to read "New password:" and "Retype new password:"
    from the process.
3. Why is my write being ignored?




More information about the Python-list mailing list