Skip to content

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

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.

Activity

  1. alexcrichton commented on Jun 24, 2014

    @alexcrichton
    MemberAuthor

    Note that the test is just copying itself to a temporary directory and then running it from the temporary directory via PATH (cutting through the irrelevant bits)

  2. wycats commented on Jun 24, 2014

    @wycats
    Contributor

    The Unix behavior sounds right to me.

  3. alexcrichton commented on Jun 24, 2014

    @alexcrichton
    MemberAuthor

    I have a proposed fix with libuv to fix the libgreen side of things: joyent/libuv#1337

  4. 6 remaining items

  5. added a commit that references this issue on Aug 12, 2014
  6. added a commit that references this issue on Sep 2, 2014
  7. added a commit that references this issue on Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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