process: script_exit_code should not leak output

This commit is contained in:
Vicki Pfau 2024-08-02 18:59:56 -07:00
parent 370c801796
commit 4cc4c74ff0

View file

@ -8,14 +8,20 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use std::ffi::OsStr; use std::ffi::OsStr;
#[cfg(not(test))] #[cfg(not(test))]
use std::process::Stdio;
#[cfg(not(test))]
use tokio::process::Command; use tokio::process::Command;
#[cfg(not(test))] #[cfg(not(test))]
pub async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<i32> { pub async fn script_exit_code(executable: &str, args: &[impl AsRef<OsStr>]) -> Result<i32> {
// Run given script and return the exit code // Run given script and return the exit code
let mut child = Command::new(executable).args(args).spawn()?; let output = Command::new(executable)
let status = child.wait().await?; .args(args)
status.code().ok_or(anyhow!("Killed by signal")) .stdout(Stdio::null())
.stderr(Stdio::null())
.output()
.await?;
output.status.code().ok_or(anyhow!("Killed by signal"))
} }
#[cfg(test)] #[cfg(test)]