[Tutor] Obtaining result from a sendline

Steven D'Aprano steve at pearwood.info
Wed Oct 31 10:35:59 CET 2012


On 31/10/12 12:47, Dave Wilder wrote:

> When I do an ssh in python (version 2.7.3) to a device, I am trying
>to capture the output of the command.
>
> However, all I get back is a numerical value.  I am looking to get
> the actual output from the "ls /var/tmp" command below.  This is
>probably readily available info, but I am just not searching on the
> python sites correctly.
>
>
>
> e.g.
>
> (Pdb) ssh = sshClient.pxssh()
> (Pdb) ssh.login(server=ip_addr, username=user, password=pswd)
> True
> (Pdb) str = ssh.sendline('ls /var/tmp')
> (Pdb) str
> 12
> (Pdb)


I'm rather surprised that you are using the Python debugger to
experiment with this. I don't think I've seen anyone else do that
before. Normally people just use the interactive shell.

What's sshClient and where did it come from? When I try to import
it, I get this error:

py> import sshClient
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named 'sshClient'


Since you haven't told us what sshClient is, and it's not a
standard part of Python, that makes it a *little* difficult to
tell you what the answer to your problem is.




-- 
Steven


More information about the Tutor mailing list