pub async fn run_command_with_timeout(cmd: &str, timeout: u64) -> Result<Output, Error> {
    // Because std::command does not give me the ability to override / modify
    // how arguments are escaped I have to do some stupid hack to make this
    // work. For example, if I wanted to run
    // podman run rustbot:latest ls -al
    // this would be impossible if I did
    //
    //  std::process::Command::new("podman")
    //    .args(["run", "rustbot:latest", "ls -al"])
    //    .output()
    //    .expect("failed to invoke container");
    //
    // As the ls -al would be quoted, and the container would try to execute
    // `ls -al` which would fail. The alternative is to seperate "ls", "-al"
    // which would also fail as the container would run `ls` then `-al`
    // ... what a stupid design
    // So instead of embracing the safety this API gives you, i'm just invoking
    // a shell with a payload I deem as safe
    let process = Command::new("sh")
        .args(["-c", cmd])
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()?;

    let output = process
        .controlled_with_output()
        .time_limit(Duration::from_millis(timeout))
        .terminate_for_timeout()
        .wait()?
        .ok_or_else(|| io::Error::new(io::ErrorKind::TimedOut, "Process timed out"));

    output
}
/// Provides a uniform way of running a command with a timeout
Provides a uniform way of running a command with a timeout
Provides a uniform way of running a command with a timeout
pub async fn run_command_with_timeout(cmd: &str, timeout: u64) -> Result<Output, Error> {
    // Because std::command does not give me the ability to override / modify
    // how arguments are escaped I have to do some stupid hack to make this
    // work. For example, if I wanted to run
    // podman run rustbot:latest ls -al
    // this would be impossible if I did
    //
    //  std::process::Command::new("podman")
    //    .args(["run", "rustbot:latest", "ls -al"])
    //    .output()
    //    .expect("failed to invoke container");
    //
    // As the ls -al would be quoted, and the container would try to execute
    // `ls -al` which would fail. The alternative is to seperate "ls", "-al"
    // which would also fail as the container would run `ls` then `-al`
    // ... what a stupid design
    // So instead of embracing the safety this API gives you, i'm just invoking
    // a shell with a payload I deem as safe
    let process = Command::new("sh")
        .args(["-c", cmd])
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()?;
    let output = process
        .controlled_with_output()
        .time_limit(Duration::from_millis(timeout))
        .terminate_for_timeout()
        .wait()?
        .ok_or_else(|| io::Error::new(io::ErrorKind::TimedOut, "Process timed out"));
    output
}
pub async fn run_command_with_timeout ( cmd : & str , timeout : u64 ) -> Result < Output , Error > { // Because std::command does not give me the ability to override / modify // how arguments are escaped I have to do some stupid hack to make this // work. For example, if I wanted to run // podman run rustbot:latest ls -al // this would be impossible if I did // //  std::process::Command::new("podman") //    .args(["run", "rustbot:latest", "ls -al"]) //    .output() //    .expect("failed to invoke container"); // // As the ls -al would be quoted, and the container would try to execute // `ls -al` which would fail. The alternative is to seperate "ls", "-al" // which would also fail as the container would run `ls` then `-al` // ... what a stupid design // So instead of embracing the safety this API gives you, i'm just invoking // a shell with a payload I deem as safe let process = Command :: new ( " " ) . args ( [ " " , cmd ] ) . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: piped ( ) ) . spawn ( ) ? ; let output = process . controlled_with_output ( ) . time_limit ( Duration :: from_millis ( timeout ) ) . terminate_for_timeout ( ) . wait ( ) ? . ok_or_else ( | | io :: Error :: new ( io :: ErrorKind :: TimedOut , " " ) ) ; output }
Provides a uniform way of running a command with a timeout
Provides a uniform way of running a command with a timeout
cmd
&str
timeout
u64
cmd
&str
timeout
u64