diff options
Diffstat (limited to 'crates/asist-tools/src/search.rs')
| -rw-r--r-- | crates/asist-tools/src/search.rs | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/crates/asist-tools/src/search.rs b/crates/asist-tools/src/search.rs index b69c17d..2d26020 100644 --- a/crates/asist-tools/src/search.rs +++ b/crates/asist-tools/src/search.rs @@ -6,10 +6,10 @@ //! acompañan como respaldo cuando no hay síntesis. use std::path::PathBuf; -use std::process::{Command, Stdio}; use std::time::{Duration, Instant}; use asist_core::error::{Error, Result}; +use asist_core::proc; use asist_core::tools::Tool; use serde_json::{json, Value}; @@ -125,38 +125,12 @@ impl WebSearch { // Los argumentos van al `execve` tal cual: la consulta sale de lo que // se ha oído por el micrófono, y no puede acabar interpretada por una // shell. - let mut child = Command::new(program) - .args(&rendered) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .map_err(|e| Self::fail(format!("no se pudo ejecutar {}: {e}", program.display())))?; - - let deadline = Instant::now() + self.timeout; - loop { - match child.try_wait().map_err(|e| Self::fail(e.to_string()))? { - Some(_) => break, - None if Instant::now() >= deadline => { - let _ = child.kill(); - let _ = child.wait(); - return Err(Self::fail(format!( - "el buscador tardó más de {} s", - self.timeout.as_secs() - ))); - } - None => std::thread::sleep(Duration::from_millis(20)), - } - } - - let output = child - .wait_with_output() + let output = proc::run(program, &rendered, self.timeout, None) .map_err(|e| Self::fail(e.to_string()))?; - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr); + if !output.success() { return Err(Self::fail(format!( "el buscador falló: {}", - stderr.trim().lines().next_back().unwrap_or("sin detalles") + output.last_error_line() ))); } |