File: windows-command.rs

package info (click to toggle)
rust-async-io 2.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (2)
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.");
}