Replacing os.popen() : subprocess « Buildin Module « Python Tutorial






from subprocess import Popen, PIPE
f = Popen(('uname', '-a'), stdout=PIPE).stdout
data = f.readline()
f.close()
print data,
        
f = Popen('who', stdout=PIPE).stdout
data = [ eachLine.strip() for eachLine in f ]
f.close()
for eachLine in data:
   print eachLine








14.15.subprocess
14.15.1.Replacing os.system()
14.15.2.Win32 Example
14.15.3.Replacing os.popen()