def execute_command(self, command, content=None, cwd=None):
pipe = subprocess.Popen(command, shell=True, cwd=cwd,
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
if content:
content = smart_bytes(content)
stdout, stderr = pipe.communicate(content)
if isinstance(stderr, bytes):
try:
stderr = stderr.decode()
except UnicodeDecodeError:
pass
if stderr.strip():
raise CompilerError(stderr, error_output=stderr)
if self.verbose:
print(stderr)
if pipe.returncode != 0:
msg = "Command '{0}' returned non-zero exit status {1}".format(command, pipe.returncode)
raise CompilerError(msg, error_output=msg)
return stdout
评论列表
文章目录