operations.py 文件源码

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

项目:picoCTF 作者: picoCTF 项目源码 文件源码
def execute(cmd, timeout=60, **kwargs):
    """
    Executes the given shell command

    Args:
        cmd: List of command arguments
        timeout: maximum alloted time for the command
        **kwargs: passes to LocalShell.spawn
    Returns:
        An execution result.
    Raises:
        NoSuchCommandError, RunProcessError, FileNotFoundError
    """

    shell = LocalShell()

    #It is unlikely that someone actually intends to supply
    #a string based on how spur works.
    if type(cmd) == str:
        cmd = ["bash", "-c"] + [cmd]

    process = shell.spawn(cmd, store_pid=True, **kwargs)
    start_time = time()

    while process.is_running():
        delta_time = time() - start_time
        if delta_time > timeout:
            process.send_signal(SIGKILL)
            raise TimeoutError(cmd, timeout)

    return process.wait_for_result()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号