[Tutor] how to control putty window

Ufuk Eskici ufukeskici at gmail.com
Fri Dec 21 18:00:31 CET 2012


I used this code:

os.chdir("c:\\Program Files\\Putty")
cmd = "plink -ssh -l ufuk 10.10.10.10 -pw password"
process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate ()

After running this code, just one black cmd screen appears, but it frezzes
and doesn't continue.

I close the window manually and when I write - *print (stdout)* - I can get
some output *"......ufuk at home-ubuntu:~$ "* - as a long string.

But I dont know why it freezes and why I cannot input anything. How should
I continue?


2012/12/21 Prasad, Ramit <ramit.prasad at jpmorgan.com>

> Ufuk Eskici wrote:
> > Hello,
> >
> > I changed my way. This time I'm using "plink" under Putty.
> >
> > My python code is:
> >
> > os.chdir("c:\\Program Files\\Putty")
> > cmd = "plink -ssh -l ufuk10.10.10.10 -pw password"
> > process = subprocess.Popen(cmd)
> > inputdata="r van"
> > result = process.communicate(inputdata)
> >
> > But after the successful SSH, I cannot continue, no command runs:
> > This is the new output after the initial SSH connection:
> > No data input.
> >
> > Last login: Fri Dec 21 16:27:
> > ufuk at home-ubuntu:~$
>
> I am not familiar with plink, so I cannot help you. I recommend using
> an SSH module which help a lot with all of this. That being said, maybe
> this post will help:
> http://code.activestate.com/lists/python-tutor/74807/
>
> Also take a look at the subprocess.communicate documentation[1] as
> it says
> """ 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.
> communicate() returns a tuple (stdoutdata, stderrdata).
> 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.
> """ (emphasis added)
> This suggests communicate is waiting for the plink to end? Also, you
> should probably pass in a pipe so that you can send data more than
> once.  Note, I am not familiar with subprocess so YMMV.
>
> [1]
> http://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.communicate
>
>
>
> Ramit
>
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121221/ed7fa661/attachment.html>


More information about the Tutor mailing list