Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions library/std/src/sys/process/windows/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{Arg, make_command_line};
use crate::env;
use crate::ffi::{OsStr, OsString};
use crate::process::Command;
use crate::os::windows::io::AsHandle;
use crate::process::{Command, Stdio};

#[test]
fn test_raw_args() {
Expand Down Expand Up @@ -29,19 +30,30 @@ fn test_thread_handle() {
use crate::os::windows::process::{ChildExt, CommandExt};
const CREATE_SUSPENDED: u32 = 0x00000004;

let p = Command::new("cmd").args(&["/C", "exit 0"]).creation_flags(CREATE_SUSPENDED).spawn();
let p = Command::new("whoami").stdout(Stdio::null()).creation_flags(CREATE_SUSPENDED).spawn();
assert!(p.is_ok());
let mut p = p.unwrap();

// Ensure the process is killed in the event something goes wrong.
struct DropGuard(crate::process::Child);
impl Drop for DropGuard {
fn drop(&mut self) {
let _ = self.0.kill();
}
}
let mut p = DropGuard(p.unwrap());
let p = &mut p.0;

unsafe extern "system" {
fn ResumeThread(_: BorrowedHandle<'_>) -> u32;
unsafe fn ResumeThread(hHandle: BorrowedHandle<'_>) -> u32;
unsafe fn WaitForSingleObject(hHandle: BorrowedHandle<'_>, dwMilliseconds: u32) -> u32;
}
unsafe {
ResumeThread(p.main_thread_handle());
// Wait until the process exits or 1 minute passes.
// We don't bother checking the result here as that's done below using `try_wait`.
WaitForSingleObject(p.as_handle(), 1000 * 60);
}

crate::thread::sleep(crate::time::Duration::from_millis(100));

let res = p.try_wait();
assert!(res.is_ok());
assert!(res.unwrap().is_some());
Expand Down
Loading