homework_checker/core/tools.py
def run_command(
    command: Union[List[str], str],
    timeout: float,
    shell: bool = True,
    cwd: Path = Path.cwd(),
    env: Optional[Mapping[str, Any]] = None,
) -> CmdResult:
    """Run a generic command in a subprocess.

    Args:
        command (str): command to run
    Returns:
        str: raw command output
    """
    try:
        startupinfo = None
        if shell and isinstance(command, list):
            command = subprocess.list2cmdline(command)
            log.debug("running command: \n%s", command)
        if env is None:
            env = environ
        process = __run_subprocess(
            command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=shell,
            cwd=str(cwd),
            env=env,
            startupinfo=startupinfo,
            timeout=timeout,
        )
        return CmdResult(
            returncode=process.returncode,
            stdout=process.stdout.decode("utf-8"),
            stderr=process.stderr.decode("utf-8"),
        )
    except subprocess.CalledProcessError as error:
        output_text = error.output.decode("utf-8")
        log.error("command '%s' finished with code: %s", error.cmd, error.returncode)
        log.debug("command output: \n%s", output_text)
        return CmdResult(returncode=error.returncode, stderr=output_text)
    except subprocess.TimeoutExpired as error:
        output_text = "Timeout: command '{}' ran longer than {} seconds".format(
            error.cmd.strip(), error.timeout
        )
        log.error(output_text)
        return CmdResult(returncode=1, stderr=output_text)
Run a generic command in a subprocess.

    Args:
        command (str): command to run
    Returns:
        str: raw command output
    
Run a generic command in a subprocess.
Run a generic command in a subprocess .
def run_command(
    command: Union[List[str], str],
    timeout: float,
    shell: bool = True,
    cwd: Path = Path.cwd(),
    env: Optional[Mapping[str, Any]] = None,
) -> CmdResult:
    try:
        startupinfo = None
        if shell and isinstance(command, list):
            command = subprocess.list2cmdline(command)
            log.debug("running command: \n%s", command)
        if env is None:
            env = environ
        process = __run_subprocess(
            command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=shell,
            cwd=str(cwd),
            env=env,
            startupinfo=startupinfo,
            timeout=timeout,
        )
        return CmdResult(
            returncode=process.returncode,
            stdout=process.stdout.decode("utf-8"),
            stderr=process.stderr.decode("utf-8"),
        )
    except subprocess.CalledProcessError as error:
        output_text = error.output.decode("utf-8")
        log.error("command '%s' finished with code: %s", error.cmd, error.returncode)
        log.debug("command output: \n%s", output_text)
        return CmdResult(returncode=error.returncode, stderr=output_text)
    except subprocess.TimeoutExpired as error:
        output_text = "Timeout: command '{}' ran longer than {} seconds".format(
            error.cmd.strip(), error.timeout
        )
        log.error(output_text)
        return CmdResult(returncode=1, stderr=output_text)
def run_command ( command : Union [ List [ str ] , str ] , timeout : float , shell : bool = True , cwd : Path = Path . cwd ( ) , env : Optional [ Mapping [ str , Any ] ] = None , ) -> CmdResult : try : startupinfo = None if shell and isinstance ( command , list ) : command = subprocess . list2cmdline ( command ) log . debug ( "running command: \n%s" , command ) if env is None : env = environ process = __run_subprocess ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = shell , cwd = str ( cwd ) , env = env , startupinfo = startupinfo , timeout = timeout , ) return CmdResult ( returncode = process . returncode , stdout = process . stdout . decode ( "utf-8" ) , stderr = process . stderr . decode ( "utf-8" ) , ) except subprocess . CalledProcessError as error : output_text = error . output . decode ( "utf-8" ) log . error ( "command '%s' finished with code: %s" , error . cmd , error . returncode ) log . debug ( "command output: \n%s" , output_text ) return CmdResult ( returncode = error . returncode , stderr = output_text ) except subprocess . TimeoutExpired as error : output_text = "Timeout: command '{}' ran longer than {} seconds" . format ( error . cmd . strip ( ) , error . timeout ) log . error ( output_text ) return CmdResult ( returncode = 1 , stderr = output_text )
Run a generic command in a subprocess.
Run a generic command in a subprocess .
"""Run a generic command in a subprocess.

    Args:
        command (str): command to run
    Returns:
        str: raw command output
    """
raw command output
raw command output
str
command
Union[List[str], str]
command to run
command to run
timeout
float
shell
bool
cwd
Path
env
Optional[Mapping[str, Any]]