[Tutor] Python popen command using cat > textfile .... how toterminate

Alan Gauld alan.gauld at btinternet.com
Fri May 15 01:48:11 CEST 2009


"vince spicer" <vinces1979 at gmail.com> wrote

> Take a peak at commands.getoutput

Or more "correctly" look at the subprocess module.
All previous mechanisms for process control are rendered
obsolete and are deprecated in favour of subprocess

So if we aren't using popen lets at least use subprocess.

It is slightly more complex than popen or commands but
it is future proof (for now at least!)

Simple example:

import subprocess
lsout = subprocess.Popen('ls -ls', shell=True, 
stdout=subprocess.PIPE).stdout
print lsout.read()

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list