1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
//! Runs a command using waitable handles on Windows.
//!
//! Run with:
//!
//! ```
//! cargo run --example windows-command
//! ```
#[cfg(windows)]
fn main() -> std::io::Result<()> {
use async_io::os::windows::Waitable;
use std::process::Command;
futures_lite::future::block_on(async {
// Spawn a process.
let process = Command::new("cmd")
.args(["/C", "echo hello"])
.spawn()
.expect("failed to spawn process");
// Wrap the process in an `Async` object that waits for it to exit.
let process = Waitable::new(process)?;
// Wait for the process to exit.
process.ready().await?;
Ok(())
})
}
#[cfg(not(windows))]
fn main() {
println!("This example is only supported on Windows.");
}
|