def run_command(command, shell=True, cwd=path.curdir, env=environ):
"""Run a generic command in a subprocess.
Args:
command (str): command to run
Returns:
str: raw command output
"""
try:
stdin = None
startupinfo = None
if isinstance(command, list):
command = subprocess.list2cmdline(command)
log.debug("running command: \n%s", command)
if sublime.platform() == "windows":
# Don't let console window pop-up briefly.
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
stdin = subprocess.PIPE
output = subprocess.check_output(command,
stdin=stdin,
stderr=subprocess.STDOUT,
shell=shell,
cwd=cwd,
env=env,
startupinfo=startupinfo)
output_text = ''.join(map(chr, output))
except subprocess.CalledProcessError as e:
output_text = e.output.decode("utf-8")
log.debug("command finished with code: %s", e.returncode)
log.debug("command output: \n%s", output_text)
return output_text
评论列表
文章目录