def do_run(cmd):
try:
cwd = os.getcwd() if inherit_cwd else None
if not async:
if stdin:
return subprocess.check_output(cmd, shell=True,
stderr=stderr, stdin=subprocess.PIPE, env=env_dict, cwd=cwd)
output = subprocess.check_output(cmd, shell=True, stderr=stderr, env=env_dict, cwd=cwd)
return output.decode(DEFAULT_ENCODING)
# subprocess.Popen is not thread-safe, hence use a mutex here..
try:
mutex_popen.acquire()
stdin_arg = subprocess.PIPE if stdin else None
stdout_arg = open(outfile, 'wb') if isinstance(outfile, six.string_types) else outfile
process = subprocess.Popen(cmd, shell=True, stdin=stdin_arg, bufsize=-1,
stderr=stderr, stdout=stdout_arg, env=env_dict, cwd=cwd)
return process
finally:
mutex_popen.release()
except subprocess.CalledProcessError as e:
if print_error:
print("ERROR: '%s': %s" % (cmd, e.output))
raise e
评论列表
文章目录