Skip to content

Process spawning via PATH is different on unix than it is on windows #15149

Closed
@alexcrichton

Description

@alexcrichton

Due to the separate fork + exec steps on unix, the following test case passes on unix. On windows, however, the "atomic" fork + exec causes the test to fail.

Notably, on unix the child's PATH environment variable is used to lookup the program to execute, whereas on windows it uses the parent's PATH variable.

use std::os;
use std::io::{File, TempDir, Command, util, UserRWX, fs};

fn main() {
    let args = os::args();
    if args.len() > 1 && args.get(1).as_slice() == "child" {
        return assert_eq!(args.get(0).as_slice(), "mytest");
    }

    let dir = TempDir::new("mytest").unwrap();
    let me = os::self_exe_name().unwrap();
    let dest = dir.path().join("mytest");
    util::copy(&mut File::open(&me), &mut File::create(&dest)).unwrap();
    fs::chmod(&dest, UserRWX).unwrap();

    Command::new("mytest").env(&[("PATH".to_string(),
                                  dir.path().as_str().unwrap().to_string())])
                          .arg("child")
                          .spawn().unwrap();
}

The behavior of the two platforms needs to be consistent, and I believe that the unix behavior is what one would expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions