<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<small><font face="Bitstream Vera Sans Mono">You may want to try
commands module<br>
<br>
</font></small><big><font face="monospace"><small>import commands</small><br>
<small>cmd = 'ls'</small><br>
<small>status, output = commands.getstatusoutput(cmd)</small><br>
<small>print output<br>
<br>
<br>
</small></font></big><small><font face="Bitstream Vera Sans Mono">Pavithra
Hanchagaiah wrote:</font></small>
<blockquote
 cite="mid:0A5B5EB4DEDAF04B9D035BA5D4FC402001DF1E19@3b-mail.hq.local"
 type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta name="Generator" content="Microsoft Word 12 (filtered medium)">
  <style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","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;}
tt
        {mso-style-priority:99;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
  </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]-->
  <div class="Section1">
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">Hey
Kartheek,  <o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">execv()
doesn’t return any value. You can either try using
os.popen() variants for the requirement or redirect stdout to file.<o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">From
Python Docs:<o:p></o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execl</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>path, arg0, arg1, ...</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execle</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>path, arg0, arg1, ..., env</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execlp</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>file, arg0, arg1, ...</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execlpe</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>file, arg0, arg1, ..., env</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execv</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>path, args</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execve</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>path, args, env</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execvp</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>file, args</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal"><span style="display: none;"><o:p> </o:p></span></p>
  <table class="MsoNormalTable" border="0" cellpadding="0"
 cellspacing="0">
    <tbody>
      <tr>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">execvpe</span></b>(<o:p></o:p></p>
        </td>
        <td style="padding: 0in;" valign="top">
        <p class="MsoNormal"><i>file, args, env</i>)<o:p></o:p></p>
        </td>
      </tr>
    </tbody>
  </table>
  <p class="MsoNormal" style="margin-left: 0.5in;">These functions all
execute a new
program, replacing the current process; <b>they do not return.<o:p></o:p></b></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">Thanks,<o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">Pavithra
  <o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
  <div
 style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">
  <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Tahoma&quot;,&quot;sans-serif&quot;;">From:</span></b><span
 style="font-size: 10pt; font-family: &quot;Tahoma&quot;,&quot;sans-serif&quot;;">
<a class="moz-txt-link-abbreviated" href="mailto:bangpypers-bounces@python.org">bangpypers-bounces@python.org</a> [<a class="moz-txt-link-freetext" href="mailto:bangpypers-bounces@python.org">mailto:bangpypers-bounces@python.org</a>] <b>On
Behalf Of </b>KartheeK<br>
  <b>Sent:</b> Wednesday, March 19, 2008 8:52 AM<br>
  <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:bangpypers@python.org">bangpypers@python.org</a><br>
  <b>Subject:</b> [BangPypers] Redirecting output to a string<o:p></o:p></span></p>
  </div>
  <p class="MsoNormal"><o:p> </o:p></p>
  <p class="MsoNormal" style="margin-bottom: 12pt;">Hi All,<br>
  <br>
I am trying to access the contents of a file in a remote machine and
store the
contents in string.<br>
  <br>
The command,<br>
os.execv(ssh, [ssh, "-l", user, ip] + ['cat /tmp/temp.conf']<br>
works but displays the output on to the screen.<br>
  <br>
I tried,<br>
to_be_analysed_txt = os.execv(ssh, [ssh, "-l", user, ip] + ['cat
/tmp/temp.conf']<br>
but that does not work out.<br>
  <br>
Regards,<br>
  <br>
KartheeK</p>
  </div>
</blockquote>
<br>
</body>
</html>