I received a reply from the help group that suggested I added a call to flush in there, and that fixed it. The working code looks like this:<div><br></div><div><div>def setpassword(user):</div><div>    password = "passworD\n"</div>
<div>    try:</div><div>        cmd = ' passwd {0}'.format(user)</div><div>        pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)</div><div>        stderr = pipe.stdin.write(password)</div>
<div>        pipe.stdin.flush()</div><div>        time.sleep(2)</div><div>        stderr = pipe.stdin.write(password)</div><div>        pipe.stdin.flush()</div><div>        pipe.stdin.close()</div><div>        if pipe.wait() != 0:</div>
<div>            log("ERROR", "Password reset failed.\n{0}{1} generated the following error: {2}".format(p4, cmd, stderr))</div><div>    except OSError as err:</div><div>        log("ERROR", "Execution failed: {0}".format(err))</div>
<div><br></div><div>Thanks,</div><div>Rusty</div><div><br></div><br><div class="gmail_quote">On Tue, Sep 15, 2009 at 6:37 PM, Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">On Tue, Sep 15, 2009 at 4:58 PM, Russell Jackson<br>
<<a href="mailto:rusty@rcjacksonconsulting.com">rusty@rcjacksonconsulting.com</a>> wrote:<br>
> I just get an errorlevel from the executable when I read stdout, but I can't<br>
> tell what is going on because, of course, I can't tell what Popen is<br>
> actually doing. I never see the prompt from the executable that I would<br>
> expect to see when I read stdout.<br>
> I originally had the function like this:<br>
> def setpassword(user):<br>
>     password = "passworD\n"<br>
>     try:<br>
>         cmd = ' passwd {0}'.format(user)<br>
>         pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,<br>
> stderr=PIPE, universal_newlines=True)<br>
>         stdout = pipe.stdout.readline()<br>
>         stderr = pipe.stdin.write(password)<br>
>         time.sleep(1)<br>
>         stdout = pipe.stdout.readline()<br>
>         stderr = pipe.stdin.write(password)<br>
>         if pipe.stdin.close != 0:<br>
>             log("ERROR", "Password reset failed.\n{0}{1} generated the<br>
> following error: {2}".format(p4, cmd, stderr))<br>
>     except OSError as err:<br>
>         log("ERROR", "Execution failed: {0}".format(err))<br>
> but, the script just hung when I did that. I think it was stuck on the<br>
> readline, and never got anything from the process.<br>
> I didn't think that the if statement was incorrect based on examples I saw<br>
> in the docs,<br>
<br>
</div></div>I'm unable to locate any example in the subprocess docs using a<br>
similar "if". The closest is this code snippet:<br>
<br>
rc = pipe.close()<br>
if  rc != None and rc % 256:<br>
    print "There were some errors"<br>
<br>
...but that's used as an example of code *using os.popen()* in the<br>
context of how to translate it to use subprocess.Popen().<br>
<div class="im"><br>
> and the fact that it didn't complain about that part,<br>
<br>
</div>Well, you're just comparing the .close method of a file object for<br>
equality with 0, which is valid, meaningful, and well-defined (hence,<br>
no error), but not useful or relevant in this context.<br>
<div class="im"><br>
>but I'll try the close():<br>
<br>
</div>I agree with Rhodri that that "if" statement is definitely bunk.<br>
Rereading the docs, I think what was intended is:<br>
<br>
pipe.stdin.close()<br>
if pipe.wait() != 0:<br>
    log(...)<br>
<div><div></div><div class="h5"><br>
Cheers,<br>
Chris<br>
--<br>
<a href="http://blog.rebertia.com" target="_blank">http://blog.rebertia.com</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Rusty<br><br>775-636-7402 Office<br>775-851-1982 Fax<br>
</div>