Calling external programs: ioredirection
Donn Cave
donn at u.washington.edu
Wed Jun 7 11:22:22 EDT 2000
Quoth olczyk at interaccess.com (Thaddeus L. Olczyk):
| Sorry for being very brief and sctech, but my ISP news server is
| flakey right now. I can post now but maybe not in ten minutes.
|
| I want to to be able to call external programs and read their output.
| For example: I might want to call grep and look at the results one by
| one.
|
| I want to do this in order to do things similar to sh. For example:
|
| wc -l *.h *.cpp|awk 'begin int i=0; {i+=$1 } end print i;}'
As already suggested, os.popen() is good for that. You'll give
it a shell command as its first parameter, and it can include
any kind of shell expression like |, etc., because it actually
does run the shell to interpret the command. (So it's a big
potential exploit if any external data goes into the command.)
In general you can do about anything the shell can do, from
Python. The problems start when you try to use pipes to do
things that the shell can't do.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list