Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread KartheeK
Looks like that is the best available option.. Thank you all folks for your time and assistance. Regards, KartheeK Rishabh Manocha <[EMAIL PROTECTED]> wrote: In that case, why not use what gnuyoga suggested - i.e. - commands.getstatusoutput("scp ..."). If the first entry in the returned tuple i

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread Rishabh Manocha
In that case, why not use what gnuyoga suggested - i.e. - commands.getstatusoutput("scp ..."). If the first entry in the returned tuple is 0, the command executed successfully, if not, then it didn't :). I think you can trust python to get the correct exit code without actually parsing the output f

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread Anand Chitipothu
On Tue, May 13, 2008 at 3:18 PM, KartheeK <[EMAIL PROTECTED]> wrote: > Hi Rishabh, > > My script needs to fetch some critical config files from 200+ servers, > process them and put them back in place. I need to make sure at each step > that I am doing the right thing. > So, I though i would make su

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread Anand Balachandran Pillai
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 [EMAIL PROTECTED]:/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

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread KartheeK
Hi Rishabh, My script needs to fetch some critical config files from 200+ servers, process them and put them back in place. I need to make sure at each step that I am doing the right thing. So, I though i would make sure to see "100%" each time I download a config file and then only proceed fu

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread Rishabh Manocha
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

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread KartheeK
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

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread gnuyoga
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 me

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread KartheeK
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. KartheeK gnuyoga <[EMAIL PROTECTED]> wrote: KartheeK wrote: > Hi Anand, > > This works for ls, I also tried it

Re: [BangPypers] Redirection of standard output to a variable

2008-05-13 Thread gnuyoga
KartheeK wrote: Hi Anand, This works for ls, I also tried it to capture ping. But for some unknown reasons it is not able to capture scp's output. The variable f is empty. KartheeK u have to get the standard error stream as well u can take a look at commands module ex: import commands pr

Re: [BangPypers] Redirection of standard output to a variable

2008-05-12 Thread KartheeK
Hi Anand, This works for ls, I also tried it to capture ping. But for some unknown reasons it is not able to capture scp's output. The variable f is empty. KartheeK Anand Balachandran Pillai <[EMAIL PROTECTED]> wrote: Using os.popen for this is straight-forward. Example... [EMAIL PROTECTED]

Re: [BangPypers] Redirection of standard output to a variable

2008-05-12 Thread Anand Balachandran Pillai
Using os.popen for this is straight-forward. Example... [EMAIL PROTECTED] programming]$ python Python 2.4.4 (#1, Oct 23 2006, 13:58:00) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> f = os.popen("ls") >>>

Re: [BangPypers] Redirection of standard output to a variable

2008-05-11 Thread KartheeK
Hi Rishabh, Unfortunately the remote servers that house these config files do not have them on either www or ftp, my only mode of access is scp This was a good learning for me , i did not know that something like urllib existed.. Thanks for the inputs KartheeK Rishabh Manocha <[EMAIL PROTECTE

Re: [BangPypers] Redirection of standard output to a variable

2008-05-11 Thread S.Ramaswamy
> > I am trying to find a way from which I could redirect standard output to a > variable. You can redirect stdout and stderr to a file. Check out the following section from Dive into Python, that has sample code: http://www.diveintopython.org/scripts_and_streams/stdin_stdout_stderr.html Ramaswa

Re: [BangPypers] Redirection of standard output to a variable

2008-05-11 Thread Rishabh Manocha
Did you take a look at using urllib[1] or urllib2[2]?? You can use them to download your file, save it and process any meta (header) info returned. [1] - http://docs.python.org/lib/module-urllib.html [2] - http://docs.python.org/lib/module-urllib2.html Best, Rishabh On Mon, May 12, 2008 at 11:2

[BangPypers] Redirection of standard output to a variable

2008-05-11 Thread KartheeK
Hi, I am trying to find a way from which I could redirect standard output to a variable. The server I am using runs, Python 2.2.1 [subprocess module is not there, and my ops team denies for an upgrade] I am writing a script that downloads a configuration file from remote servers[200+], I want t