calling programs from python
David MacQuigg
shuvit at 127.0.0.1
Tue Dec 2 14:42:40 EST 2003
On Tue, 02 Dec 2003 16:02:26 GMT, Kristofer Wouk
<kristofer at hotpop.com> wrote:
[...]
>import os
>os.popen('command > file')
This is a little confusing. Do you intend the output from 'command'
to go to 'file' or to the pipe you just opened?
If you are opening a pipe (to be read as a file object) I would
suggest something like this:
>>> import os
>>> file = os.popen('cat makefile | grep pyuic')
>>> file.readlines()
['\tpyuic ModelSelector.ui > ModelSelector.py\n']
If you are just executing a command and not needing to process any
output from the command (other than its completion status), I would
stick with the more general:
>>> import os
>>> status = os.system('command > file')
>>> status
>>> 0
>>>
--Dave
More information about the Python-list
mailing list