How to kill a spawned process from a reading thread?

⚓ Rust    📅 2025-07-25    👤 surdeus    👁️ 2      

surdeus

I have a code like:

let mut child = Command::new(&path_translated)
         .stdout(Stdio::piped())
         .stdin(Stdio::piped())
         .stderr(Stdio::piped())
         .spawn()?;
....
 if let Some(mut stdin) = child.stdin.take() { 
         
       thread::scope(|s| {
            s.spawn(|| {
....
     child.kill().expect("Failed to kill child process");
          }
  if let Some(stderr)  = child.stderr.take() {
             s.spawn(|| {

Since child got moved in the first thread, I can't use it for taking stderr. How can I clone the child, or there is an another technique?

1 post - 1 participant

Read full topic

🏷️ Rust_feed