[Tutor] ssh from Windows to a Solaris server

Evert Rol evert.rol at gmail.com
Mon Feb 20 22:36:53 CET 2012

> I’m a newbie in python programming …
> I wrote the followings to ssh from Windows to a Solaris server:
> command1 = "plink -ssh -pw myPassword myUserName at myServerIP"
> p1 = subprocess.Popen(command1)
> p2 = subprocess.Popen('ls')
> I could verify that command1 was executed successfully, ie. the ssh to myServer worked, but command2 was treated locally in the Windows and was not executed on the server.

As far as I know subprocess, you create a completely new shell environment underneath for every process.
So essentially, you are now opening a shell, typing your ssh command, closing the shell (and thus the ssh session), and then create a new shell to type 'ls'.
You can put the commands in a single shell script and run that through subprocess. 
With ssh, it could be somewhat easier:

>>> command1 = "plink -ssh -pw myPassword myUserName at myServerIP ls"
>>> p1 = subprocess.Popen(command1)

So, you can just put the command you want to run at the end of the ssh command.
But, I don't know if plink allows that: I simply don't know plink. If it doesn't work this way, there may be an option for it though.
(Can't say I like the idea it lets you specify the password on the command line, but hey.)



>  The error was as follows:
> Traceback (most recent call last):
>   File "C:\Python32\ProgramFiles\test-paramiko.py", line 42, in <module>
>     p2 = subprocess.Popen('ls')
>   File "C:\Python32\lib\subprocess.py", line 741, in __init__
>     restore_signals, start_new_session)
>   File "C:\Python32\lib\subprocess.py", line 960, in _execute_child
>     startupinfo)
> WindowsError: [Error 2] The system cannot find the file specified
> Any hint ?  I am using python 3.2 and did try to install paramiko but could not make it works.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list