Skip to content

Commit

Permalink
cool~!
Browse files Browse the repository at this point in the history
  • Loading branch information
namse committed Dec 3, 2023
1 parent c90abbf commit 6960bdb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions oioi/agent/src/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ pub(crate) async fn run(command: impl AsRef<str>) -> Result<Vec<u8>> {
let command = command.as_ref();

let output = tokio::process::Command::new("bash")
.arg("-c")
.arg(format!(
"\"{command}\"",
command = command.replace('"', "\\\"")
))
.args(["-c", command])
.output()
.await
.map_err(|e| anyhow::anyhow!("Failed to run {command}: {e}"))?;
Expand All @@ -22,3 +18,14 @@ pub(crate) async fn run(command: impl AsRef<str>) -> Result<Vec<u8>> {

Ok(output.stdout)
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_run() {
let output = run("echo hello").await.unwrap();
assert_eq!(output, b"hello\n");
}
}

0 comments on commit 6960bdb

Please sign in to comment.