shell.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:MUBench 作者: stg-tud 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号