|  | 
| 1 | 1 | use super::{Arg, make_command_line}; | 
| 2 | 2 | use crate::env; | 
| 3 | 3 | use crate::ffi::{OsStr, OsString}; | 
| 4 |  | -use crate::process::Command; | 
|  | 4 | +use crate::os::windows::io::AsHandle; | 
|  | 5 | +use crate::process::{Command, Stdio}; | 
| 5 | 6 | 
 | 
| 6 | 7 | #[test] | 
| 7 | 8 | fn test_raw_args() { | 
| @@ -29,19 +30,30 @@ fn test_thread_handle() { | 
| 29 | 30 |     use crate::os::windows::process::{ChildExt, CommandExt}; | 
| 30 | 31 |     const CREATE_SUSPENDED: u32 = 0x00000004; | 
| 31 | 32 | 
 | 
| 32 |  | -    let p = Command::new("cmd").args(&["/C", "exit 0"]).creation_flags(CREATE_SUSPENDED).spawn(); | 
|  | 33 | +    let p = Command::new("whoami").stdout(Stdio::null()).creation_flags(CREATE_SUSPENDED).spawn(); | 
| 33 | 34 |     assert!(p.is_ok()); | 
| 34 |  | -    let mut p = p.unwrap(); | 
|  | 35 | + | 
|  | 36 | +    // Ensure the process is killed in the event something goes wrong. | 
|  | 37 | +    struct DropGuard(crate::process::Child); | 
|  | 38 | +    impl Drop for DropGuard { | 
|  | 39 | +        fn drop(&mut self) { | 
|  | 40 | +            let _ = self.0.kill(); | 
|  | 41 | +        } | 
|  | 42 | +    } | 
|  | 43 | +    let mut p = DropGuard(p.unwrap()); | 
|  | 44 | +    let p = &mut p.0; | 
| 35 | 45 | 
 | 
| 36 | 46 |     unsafe extern "system" { | 
| 37 |  | -        fn ResumeThread(_: BorrowedHandle<'_>) -> u32; | 
|  | 47 | +        unsafe fn ResumeThread(hHandle: BorrowedHandle<'_>) -> u32; | 
|  | 48 | +        unsafe fn WaitForSingleObject(hHandle: BorrowedHandle<'_>, dwMilliseconds: u32) -> u32; | 
| 38 | 49 |     } | 
| 39 | 50 |     unsafe { | 
| 40 | 51 |         ResumeThread(p.main_thread_handle()); | 
|  | 52 | +        // Wait until the process exits or 1 minute passes. | 
|  | 53 | +        // We don't bother checking the result here as that's done below using `try_wait`. | 
|  | 54 | +        WaitForSingleObject(p.as_handle(), 1000 * 60); | 
| 41 | 55 |     } | 
| 42 | 56 | 
 | 
| 43 |  | -    crate::thread::sleep(crate::time::Duration::from_millis(100)); | 
| 44 |  | - | 
| 45 | 57 |     let res = p.try_wait(); | 
| 46 | 58 |     assert!(res.is_ok()); | 
| 47 | 59 |     assert!(res.unwrap().is_some()); | 
|  | 
0 commit comments