def get_command_output(cmd, and_stderr=False):
""" Return a pipe from which a command's output can be read. cmd is the
command. and_stderr is set if the output should include stderr as well as
stdout.
"""
try:
import subprocess
except ImportError:
if and_stderr:
_, sout = os.popen4(cmd)
else:
_, sout, _ = os.popen3(cmd)
return sout
if and_stderr:
stderr = subprocess.STDOUT
else:
stderr = subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=stderr)
return p.stdout
评论列表
文章目录