<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoPlainText">Sorry for the poor  info on my part Steven et al.  I did not do my homework.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">I thought that sshclient was an imported module, however it is pxssh that I am importing as sshClient.<o:p></o:p></p>
<p class="MsoPlainText"><span style="font-size:10.0pt;font-family:"Courier New"">import pxssh as sshClient<o:p></o:p></span></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">There is no particular reason I need to debug this using the debugger to troubleshoot this.  I was just using it to step through the program at the time.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Thank you eryksun for the help…especially the quick response and great explanation. Both of your suggestions will  work for me, particularly the 2<sup>nd</sup>  one.
<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">I am not actually using “str” for the reasons you described.  I just renamed it when I emailed my question, which was probably not a good idea.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Thanks,<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Dave<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">-----Original Message-----<br>
From: eryksun [mailto:eryksun@gmail.com] <br>
Sent: Wednesday, October 31, 2012 1:44 AM<br>
To: Dave Wilder<br>
Cc: tutor@python.org<br>
Subject: Re: [Tutor] Obtaining result from a sendline</p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">On Tue, Oct 30, 2012 at 9:47 PM, Dave Wilder <<a href="mailto:D.Wilder@f5.com"><span style="color:windowtext;text-decoration:none">D.Wilder@f5.com</span></a>> wrote:<o:p></o:p></p>
<p class="MsoPlainText">><o:p> </o:p></p>
<p class="MsoPlainText">> However, all I get back is a numerical value.  I am looking to get the
<o:p></o:p></p>
<p class="MsoPlainText">> actual output from the “ls /var/tmp”<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">That would be the number of bytes sent.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">> ssh = sshClient.pxssh()<o:p></o:p></p>
<p class="MsoPlainText">> ssh.login(server=ip_addr, username=user, password=pswd) str =
<o:p></o:p></p>
<p class="MsoPlainText">> ssh.sendline('ls /var/tmp')<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">It's not a good idea to shadow the name of the built-in type str.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">The pxssh object should have the methods read, read_nonblocking, readline, and readlines. But you probably want the output from between prompts. The prompt() method calls expect() to match the custom prompt, and returns False if there's
 a timeout (the default is 20 seconds). This sets the instance attribute "before" with the text that came before the match:<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">    ssh.sendline('ls /var/tmp')<o:p></o:p></p>
<p class="MsoPlainText">    if ssh.prompt():<o:p></o:p></p>
<p class="MsoPlainText">        output = ssh.before<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Alternatively, if you've setup a public key on the host via ssh-keygen, you could use subprocess.check_output() instead:<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">    import subprocess<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">    cmd = ['ssh', '-l', login, hostname, 'ls /var/tmp']<o:p></o:p></p>
<p class="MsoPlainText">    output = subprocess.check_output(cmd)<o:p></o:p></p>
</div>
</body>
</html>