def exec(command: str, cwd: str = os.getcwd(), logger=logging.getLogger(__name__), timeout: Optional[int] = None):
logger.debug("Execute '%s' in '%s'", command, cwd)
encoding = Shell.__get_encoding()
try:
# On our Debian server subprocess does not return until after the process finished, but then correctly
# raises TimeoutExpired, if the process took to long. We use `timeout` to ensure that the process terminates
# eventually.
if "Linux" in platform() and timeout is not None:
command = "timeout {} {}".format(timeout + 60, command)
output = Shell.__exec(command, cwd, timeout, encoding)
logger.debug(output)
return output
except CalledProcessError as e:
raise CommandFailedError(e.cmd, e.output.decode(encoding), e.stderr.decode(encoding))
except TimeoutExpired as e:
raise TimeoutError(e.cmd, e.output.decode(encoding))
评论列表
文章目录