[BangPypers] Redirection of standard output to a variable
Anand Balachandran Pillai
abpillai at gmail.com
Tue May 13 11:52:15 CEST 2008
This is not an easy thing to do. You can capture any error output by scp
by redirecting the error stream,
For example,
$ scp names.txt anand at remote-host:/home/anand 2>out.txt
$ more out.txt
names.txt: no such file or directory
However trying to capture the output stream (with no error) does not seem
to work.
$ scp names.txt anand at remote-host:/home/anand 1>out.txt
$ more out.txt
out.txt (END)
Try the verbose mode of scp. Using this mode more information is printed
to stderr, which can be captured in a file.
$ scp -v names.txt anand at remote-host:/home/anand 2>out.txt
$ tail out.txt
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: scp -v -t /home/anand
Sending file modes: C0644 6 names.txt
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 2.8 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
Ideally, any code should not be relying on the output of such programs
and instead
should look at the exit status. If you can tell us why you want to
parse the output
of scp, we can advise you better.
--Anand
On Tue, May 13, 2008 at 2:59 PM, Rishabh Manocha <rmanocha at gmail.com> wrote:
> Kartheek,
>
> It seems like what you want to do is a bit complicated -
> http://www.linuxquestions.org/questions/linux-general-1/how-to-redirect-the-scp-command-output-to-text-file.-629034/.
> Maybe if you can explain why you need the exact string that scp
> outputs, somebody can suggest alternatives.
>
> Best,
>
> R
>
>
>
> On Tue, May 13, 2008 at 2:42 PM, KartheeK <kartheekpn at yahoo.co.in> wrote:
> > A typical scp transaction would result in an output as below:
> > -------------------------------------------------------
> > temp.conf 100% 23
> > 0.0KB/s 00:00
> > -------------------------------------------------------
> > I am interested in capturing the above output in a string.
> >
> >
> > gnuyoga <gnuyoga at gmail.com> wrote:
> >
> > KartheeK wrote:
> > > Hi,
> > >
> > > I tried that too but it also for some reasons fails to capture scp
> > > output although it can capture things like ping.
> > > command.getstatusoutput returns exit code but not the string.
> >
> > what do u mean by scp output ?
> >
> > commands.getstatusoutput will give you output status and message if any
> >
> > if 0 means the command is executed sucessfully.
> > else it failed and reason why it failed will be returned.
> >
> >
> > please remember that we cannot see you monitor ;-)
> >
> > - sree
> >
> > --
> > http://picasaweb.google.com/gnuyoga
> >
> > Each soul is potentially divine. The goal is to manifest the divine by
> > controlling nature, internal or external. Do this by work or worship or
> > psychic control or philosophy by one or more, or all of these and be free.
> >
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > http://mail.python.org/mailman/listinfo/bangpypers
> >
> >
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > http://mail.python.org/mailman/listinfo/bangpypers
> >
> >
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
-Anand
More information about the BangPypers
mailing list