Easy way to store stdout to a variable?

mike mmarsh at di.mdacc.tmc.edu
Sun Mar 9 23:41:45 EST 2003


Hi,

I am a python newbie and am trying to migrate my simple shell-script
tasks to python.  When writing shell scripts, I make common use of
unix pipes and filters, e.g. "ls *.txt | grep -v old | wc -l".

I know I can use "os.system()" to invoke system calls, but I don't
know how to store the stdout of the system call into a python
variable.

I realize I could do all of my filtering in python, but who wants to
rewrite grep and the hundred other unix tools?

So what is an easy one-liner way to store stdout of a sytem-call to a
variable?

Thanks in advance,
mike




More information about the Python-list mailing list