I just get an errorlevel from the executable when I read stdout, but I can't tell what is going on because, of course, I can't tell what Popen is actually doing. I never see the prompt from the executable that I would expect to see when I read stdout.<div>
<br></div><div>I originally had the function like this:</div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><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> stdout = pipe.stdout.readline()</div><div> stderr = pipe.stdin.write(password)</div><div> time.sleep(1)</div><div> stdout = pipe.stdout.readline()</div><div><div> stderr = pipe.stdin.write(password)</div>
<div> if pipe.stdin.close != 0:</div></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></span></div><div>but, the script just hung when I did that. I think it was stuck on the readline, and never got anything from the process.</div>
<div><br></div><div>I didn't think that the if statement was incorrect based on examples I saw in the docs, and the fact that it didn't complain about that part, but I'll try the close():</div><div><br></div><div>
Thanks,</div><div>Rusty</div><div><br></div><div><br><br><div class="gmail_quote">On Tue, Sep 15, 2009 at 4:24 PM, Rhodri James <span dir="ltr"><<a href="mailto:rhodri@wildebst.demon.co.uk">rhodri@wildebst.demon.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Wed, 16 Sep 2009 00:01:17 +0100, Russell Jackson <<a href="mailto:rusty@rcjacksonconsulting.com" target="_blank">rusty@rcjacksonconsulting.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
I have the following code that works fine in Python 2.x, but I can't seem to<br>
get it to work in Python 3 with Popen. Can you please tell me how to get the<br>
same functionality out of Python 3? The gist of what I doing is in the<br>
setpassword function. I have tried numerous ways to get this to work, and<br>
just can't figure it out, and the docs on Popen are no help whatsoever on<br>
how to use the now open process. The examples completely skip over what to<br>
do with the process after you open it.<br>
</blockquote>
<br></div>
So how did it fail?<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
###############################################################################<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>
stderr = pipe.stdin.write(password)<br>
time.sleep(1)<br>
stderr = pipe.stdin.write(password)<br>
if pipe.stdin.close != 0:<br>
</blockquote>
<br></div>
Did you perhaps mean "if pipe.stdin.close():" ?<br>
Does it help if you read stdout rather than sleeping for arbitrary periods?<br>
<br>
-- <br>
Rhodri James *-* Wildebeest Herder to the Masses<br><font color="#888888">
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Rusty<br><br>775-636-7402 Office<br>775-851-1982 Fax<br>
</div>