I wrote following program for an example --
from subprocess import *
import shlex
def pipe(command):
proc = Popen(shlex.split(command), stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
print "output:", out # blank
print "errors:", err # expected output
#return str(err) # returns expected output
return str(out) # returns blanked output
out = pipe('python --version')
print 'pipe returned ----- %s' % out
Actually, err holds the expected value instead of out.
- What is wrong with this code?
- Is subprocess module is only used to handle basic OS's commands?