<div dir="ltr">I used this code:<div><br></div><div><div>os.chdir("c:\\Program Files\\Putty")</div><div>cmd = "plink -ssh -l ufuk 10.10.10.10 -pw password"</div><div>process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=subprocess.PIPE)</div>
<div>stdout, stderr = process.communicate ()</div></div><div><br></div><div style>After running this code, just one black cmd screen appears, but it frezzes and doesn't continue.</div><div style><br></div><div style>I close the window manually and when I write - <b>print (stdout)</b> - I can get some output <b>"......ufuk@home-ubuntu:~$ "</b> - as a long string.</div>
<div style><br></div><div style>But I dont know why it freezes and why I cannot input anything. How should I continue?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2012/12/21 Prasad, Ramit <span dir="ltr"><<a href="mailto:ramit.prasad@jpmorgan.com" target="_blank">ramit.prasad@jpmorgan.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ufuk Eskici wrote:<br>
> Hello,<br>
><br>
<div class="im">> I changed my way. This time I'm using "plink" under Putty.<br>
><br>
> My python code is:<br>
><br>
> os.chdir("c:\\Program Files\\Putty")<br>
> cmd = "plink -ssh -l ufuk10.10.10.10 -pw password"<br>
> process = subprocess.Popen(cmd)<br>
> inputdata="r van"<br>
> result = process.communicate(inputdata)<br>
><br>
> But after the successful SSH, I cannot continue, no command runs:<br>
> This is the new output after the initial SSH connection:<br>
> No data input.<br>
><br>
> Last login: Fri Dec 21 16:27:<br>
> ufuk@home-ubuntu:~$<br>
<br>
</div>I am not familiar with plink, so I cannot help you. I recommend using<br>
an SSH module which help a lot with all of this. That being said, maybe this post will help:<br>
<a href="http://code.activestate.com/lists/python-tutor/74807/" target="_blank">http://code.activestate.com/lists/python-tutor/74807/</a><br>
<br>
Also take a look at the subprocess.communicate documentation[1] as<br>
it says<br>
""" Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. **Wait for process to terminate**. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.<br>
communicate() returns a tuple (stdoutdata, stderrdata).<br>
Note that if you want to send data to the process's stdin, you need to create the Popen object with stdin=PIPE. Similarly, to get anything other than None in the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too.<br>
""" (emphasis added)<br>
This suggests communicate is waiting for the plink to end? Also, you<br>
should probably pass in a pipe so that you can send data more than<br>
once. Note, I am not familiar with subprocess so YMMV.<br>
<br>
[1]<a href="http://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate" target="_blank">http://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
Ramit<br>
<br>
<br>
This email is confidential and subject to important disclaimers and<br>
conditions including on offers for the purchase or sale of<br>
securities, accuracy and completeness of information, viruses,<br>
confidentiality, legal privilege, and legal entity disclaimers,<br>
available at <a href="http://www.jpmorgan.com/pages/disclosures/email" target="_blank">http://www.jpmorgan.com/pages/disclosures/email</a>.<br>
</div></div></blockquote></div><br></div>