[Tutor] Getting the results of a file or command?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed Nov 13 01:05:02 2002


On Tue, 12 Nov 2002, Yigal Duppen wrote:

> > How do you get the results from the execution of a file or system
> > command?
>
> Have a look at os.popen
>
> Using this function, you get a file-like object representing stdout. You
> can then analyze the output.


By the way, we can find out more about os.popen() by looking at:

    http://www.python.org/doc/lib/os-newstreams.html#os-newstreams

Its documentation is located in an odd location, but the reason that it's
in that section is because os.popen() returns a file-like object, and is
technically a "file creation" sort of function.


(Of course, if we didn't know about the function before, it would be sorta
difficult to find it.  *grin*)


Good luck!