| 1 | #![cfg(feature = "std")] |
| 2 | |
| 3 | use io_process::{ |
| 4 | command::Command, |
| 5 | coroutines::spawn_then_wait::{SpawnThenWait, SpawnThenWaitResult}, |
| 6 | runtimes::std::handle, |
| 7 | }; |
| 8 | use tempfile::tempdir; |
| 9 | |
| 10 | fn main() { |
| 11 | env_logger::init(); |
| 12 | |
| 13 | let workdir = tempdir().unwrap(); |
| 14 | |
| 15 | let mut command = Command::new("touch"); |
| 16 | command.arg(workdir.path().join("file.tmp").to_string_lossy()); |
| 17 | |
| 18 | println!("spawn: {command:#?}"); |
| 19 | println!(); |
| 20 | |
| 21 | let mut arg = None; |
| 22 | let mut spawn = SpawnThenWait::new(command); |
| 23 | |
| 24 | let status = loop { |
| 25 | match spawn.resume(arg.take()) { |
| 26 | SpawnThenWaitResult::Ok(output) => break output, |
| 27 | SpawnThenWaitResult::Io(io) => arg = Some(handle(io).unwrap()), |
| 28 | SpawnThenWaitResult::Err(err) => panic!("{err}"), |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | println!("exit status: {status:#?}"); |
| 33 | } |