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] 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") >>> print f.read() #809.ods berkleyDB.pdf bittorrentecon.pdf btorrent_protocol_files btorrent_protocol.html c_network_prog_presentation.pdf ... You simply open a pipe to the process and read the output from the pipe. os.popen2/os.popen3 gives more control, using this you can manipulate both stdio and stdout and stdio, stdout and stderr of the process respectively. --Anand On Mon, May 12, 2008 at 12:18 PM, S.Ramaswamy wrote: >> >> 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 > > Ramaswamy > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- -Anand _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
_______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers