| 1 | #![warn (rust_2018_idioms)] |
| 2 | #![cfg (feature = "full" )] |
| 3 | #![cfg (windows)] |
| 4 | |
| 5 | use tokio::process::Command; |
| 6 | use windows_sys::Win32::System::Threading::GetProcessId; |
| 7 | |
| 8 | #[tokio::test ] |
| 9 | async fn obtain_raw_handle() { |
| 10 | let mut cmd = Command::new("cmd" ); |
| 11 | cmd.kill_on_drop(true); |
| 12 | cmd.arg("/c" ); |
| 13 | cmd.arg("pause" ); |
| 14 | |
| 15 | let child = cmd.spawn().unwrap(); |
| 16 | |
| 17 | let orig_id = child.id().expect("missing id" ); |
| 18 | assert!(orig_id > 0); |
| 19 | |
| 20 | let handle = child.raw_handle().expect("process stopped" ); |
| 21 | let handled_id = unsafe { GetProcessId(handle as _) }; |
| 22 | assert_eq!(handled_id, orig_id); |
| 23 | } |
| 24 | |