Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: how to handle output generated after execution of command/scripton host unix machine?

Reply
Thread Tools

Re: how to handle output generated after execution of command/scripton host unix machine?

 
 
Dan Stromberg
Guest
Posts: n/a
 
      12-23-2010
On Sun, Dec 19, 2010 at 11:38 PM, Darshak Bavishi
<(E-Mail Removed)> wrote:
> Hi Experts,
> I am still struggling with handling output generated after*execution*of
> *command/script on host unix machine using windows client machine
> ssh code :
> import sys
> import datetime
> import time
> # setup logging
> paramiko.util.log_to_file('darshak_simple.log')
> ssh=paramiko.SSHClient()
> ssh.set_missing_host_key_policy(paramiko.AutoAddPo licy())
> ssh.connect("*****",username="****",password="**** ")
> try:
> ** *stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d >
> /var/log/Darshak/3.txt ") // output of this command will be store in
> /var/log/Darshak/ in remote machine
> except:
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * {Issue is
> files are generating but remaining blank pls pls help me out of this}
> ** *print "check"
> time.sleep(10)
> print stdout.readlines()
> a=stdout.readlines()
> print 1
> ssh.close()
> #print stdout.readlines()
> Issue is files are generating but remaining blank pls pls help me out of
> this
> --
> BR
> Darshak Bavishi
>
> --
> BR
> Darshak Bavishi
>
> --
> http://mail.python.org/mailman/listinfo/python-list


I've never used paramiko, but I have done some python+ssh.

1) Are you wanting the output from BsPlSMProbe to go to
/var/log/Darshak/3.txt or your print stdout.readlines()? If you need
both, you'd probably better get a tee in there.

2) If /var/log/Darshak/3.txt is coming up empty, it could mean that
BsPlSMProbe simply produces no output. What if you ssh into the
server interactively (perhaps using openssh or putty), and your
command from there, as the same user, with the same options?

3) If you want errors as well as normal output in the same place, try
a 2>&1 in your shell command, assuming you're using sh/ksh/bash (POSIX
shell). You can tell what shell you're in with echo $SHELL.

4) If paramiko allows you to access the exit status of the command,
you probably should retrieve that, not just stdout (and stderr).
Conventionally, if the exit status is 0, things are fine, if they're
nonzero, something's wrong - the oppose of what you see in most other
languages that treat integers as booleans, because there are usually
more ways things can fail than succeed. In fact, strictly speaking,
the presence or absence of text on stderr is not a good indication of
an error, compared to checking the exit status.

HTH
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
An unhandled exception was generated during the execution of the current web request. Andrew III ASP .Net 1 12-18-2007 01:02 AM
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
How to send output to browser and stop execution of events occuring after load TS ASP .Net 2 01-23-2006 06:46 AM
how to handle command line output(not terminal handle) Leon Python 2 11-04-2004 05:16 AM



Advertisments