Maybe some bug in std::process::Command::new() on windows 7

I set the creation_flags to 0x00000010 to create a process with a new console.
This code works well on Windows10, but the new process throws io.excption on Windows7.
Further more, without setting creation_flag as 0x00000010, it works well on both win7 & win10.

    let res = std::process::Command::new(args.path)
        .creation_flags(0x00000010)
        .current_dir(dbg!(cd))
        .spawn()
        .unwrap();

And I tried windows on crates.io, calling windows api directly like this.

    unsafe {
        use windows::core::{PCWSTR, PWSTR};
        use windows::Win32::System::Threading::*;
        use windows::Win32::Foundation::GetLastError;

        dbg!(CreateProcessW(
            PCWSTR::null(),
            PWSTR::from_raw(cmd.as_mut_ptr()),
            None,
            None,
            true,
            CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
            None,
            PCWSTR::from_raw(cd.as_ptr()),
            &STARTUPINFOW::default(),
            &mut PROCESS_INFORMATION::default(),
        ));

        dbg!(GetLastError());
    }

It works well on both win7 & win10, and the new process has an individual console.

That's tooooo strange, and I tried to read the std::process's source code many times, but failed to figure out what is the difference.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.