| 1 | #![cfg(feature = "std")] |
| 2 | |
| 3 | use io_process::{ |
| 4 | command::Command, |
| 5 | coroutines::spawn_then_wait_with_output::{ |
| 6 | SpawnThenWaitWithOutput, SpawnThenWaitWithOutputResult, |
| 7 | }, |
| 8 | runtimes::std::handle, |
| 9 | }; |
| 10 | |
| 11 | fn main() { |
| 12 | env_logger::init(); |
| 13 | |
| 14 | let mut command = Command::new("/bin/sh"); |
| 15 | command.arg("-c"); |
| 16 | command.arg("bad command"); |
| 17 | |
| 18 | println!("spawn: {command:#?}"); |
| 19 | println!(); |
| 20 | |
| 21 | let mut arg = None; |
| 22 | let mut spawn = SpawnThenWaitWithOutput::new(command); |
| 23 | |
| 24 | let output = loop { |
| 25 | match spawn.resume(arg.take()) { |
| 26 | SpawnThenWaitWithOutputResult::Ok(output) => break output, |
| 27 | SpawnThenWaitWithOutputResult::Io(io) => arg = Some(handle(io).unwrap()), |
| 28 | SpawnThenWaitWithOutputResult::Err(err) => panic!("{err}"), |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | println!("output: {output:#?}"); |
| 33 | } |