Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SshMachine on windows with plink/pscp hangs in popen #37

Closed
replabrobin opened this issue Oct 10, 2012 · 4 comments
Closed

SshMachine on windows with plink/pscp hangs in popen #37

replabrobin opened this issue Oct 10, 2012 · 4 comments

Comments

@replabrobin
Copy link

>>> from plumbum import SshMachine
>>> from plumbum.cmd import plink, pscp
>>> rem = SshMachine('app5',ssh_command=plink,scp_command=pscp,ssh_opts=['-ssh'])
#
# wait then type ctrl+C
#
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\remote_machine.py", line 357, in __init__
    BaseRemoteMachine.__init__(self)
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\remote_machine.py", line 151, in __init__
    self._session = self.session()
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\remote_machine.py", line 381, in session
    return ShellSession(self.popen((), ["-tt"] if isatty else []), self.encoding, isatty)
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\session.py", line 132, in __init__
    self.run("")
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\session.py", line 213, in run
    return run_proc(self.popen(cmd), retcode)
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\commands.py", line 152, in run_proc
    stdout, stderr = proc.communicate()
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\session.py", line 91, in communicate
    line = pipe.readline()
  File "c:\python\lib\site-packages\plumbum-1.0.0-py2.7-win32.egg\plumbum\session.py", line 39, in readline
    line = self.pipe.readline()
KeyboardInterrupt
>>>
@obmarg
Copy link
Contributor

obmarg commented Oct 10, 2012

Quite coincidental timing on this bug report - I've just spent an hour or so trying to get this working myself. I've not been able to figure out any obvious causes, but if it helps:

It seems that the line = self.pipe.readline() function call in that stack trace gets called to read the first line from the plink process and just never returns anything. I'm not sure why, and manually using Popen to do roughly the same thing (as far as I can figure out from the plumbum.shell and plumbum.local logging) seems to work alright.

@tomerfiliba
Copy link
Owner

@replabrobin:

  1. I tried using plink & pscp for the commands in remote_command.py, but the session popen seems to hang on plink; that's true even if I use a -ssh flag etc etc.
  2. I was able to get stuff working with the ssh.exe from the windows git install, but only after ensuring that CYGWIN environment variable was deleted. My attempt to delete os.environ['CYGWIN'] in SshMachine.init didn't work I needed to do that before importing plumbum.

I would like to get the putty version of SshMachine to work and will poke about a bit more; previously I got py execnet's SshGateway to work fairly easily. I think the problem here is that plink is opened without any command.

The following seems to work well

from plumbum.cmd import plink
z=plink['-ssh','rptlab@app5',"uname -a"]
z()
u'Linux app5.reportlab.com 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:12:07 UTC 2012 x86_64 GNU/Linux\n'

@tomerfiliba
Copy link
Owner

@replabrobin, @obmarg:
The problem was, plink allocates a TTY unless -T is explicitly given. This meant that stderr is redirected to stdout, so the line stderr.readline() waited forever. I added PuttyMachine, which derives from SshMachine but makes the required changes. For example:

from plumbum import PuttyMachine, local
local.env.path.append("c:\\program files\\putty")

m=PuttyMachine("myhost", keyfile="c:\\path\\to\\my.ppk")

@replabrobin
Copy link
Author

On 20/10/2012 11:24, Tomer Filiba wrote:

@replabrobin, @obmarg:
The problem was, plink allocates a TTY unless -T is explicitly given. This meant that stderr is redirected to stdout, so the line stderr.readline() waited forever. I added PuttyMachine, which derives from SshMachine but makes the required changes. For example:

 from plumbum import PuttyMachine, local
 local.env.path.append("c:\\program files\\putty")

 m=PuttyMachine("myhost", keyfile="c:\\path\\to\\my.ppk")

.....

well detected and thanks for nice software

Robin Becker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants