os.spawn

Adam Hupp hupp at cs.wisc.edu
Tue Apr 29 09:55:54 EDT 2003


On Tue, Apr 29, 2003 at 01:29:41PM +0000, Jeroen Wolff wrote:
> Hi,
> 
> I want to run some shell commands from within python. 
> Wat i normal do at the shell prompt is:
> 'flow-cat <dirname> | flow-stat <param> > outputfile.txt'
> 
> I like to do this from within python and wait for it to finish and the 
> process the outputfile.txt
> Is this possible? The problem is with '|' and '>" piping....

You want to use os.system or os.popen.  With popen you can read the
results directly without using the intermediate file. 

os.system('flow-cat <dirname> | flow-stat <param> > outputfile.txt')

or

flow = os.popen('flow-cat <dirname> | flow-stat <param>')

for i in flow.readlines():
	...


-Adam





More information about the Python-list mailing list