cmd = shlex.split(cmdln_or_args)[0]
shell = True
- if catch != 3:
- dev_null = os.open("/dev/null", os.O_WRONLY)
-
if catch == 0:
- sout = dev_null
- serr = dev_null
+ sout = subprocess.DEVNULL
+ serr = subprocess.DEVNULL
elif catch == 1:
sout = subprocess.PIPE
- serr = dev_null
+ serr = subprocess.DEVNULL
elif catch == 2:
- sout = dev_null
+ sout = subprocess.DEVNULL
serr = subprocess.PIPE
elif catch == 3:
sout = subprocess.PIPE
serr = subprocess.STDOUT
try:
- p = subprocess.Popen(cmdln_or_args, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=shell, universal_newlines=True)
+ p = subprocess.Popen(cmdln_or_args, stdout=sout,
+ stderr=serr, shell=shell, universal_newlines=True)
(sout, serr) = p.communicate()
# combine stdout and stderr, filter None out
out = ''.join([_f for _f in [sout, serr] if _f])