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.
Due to the separate
fork+execsteps on unix, the following test case passes on unix. On windows, however, the "atomic"fork+execcauses the test to fail.Notably, on unix the child's
PATHenvironment variable is used to lookup the program to execute, whereas on windows it uses the parent'sPATHvariable.The behavior of the two platforms needs to be consistent, and I believe that the unix behavior is what one would expect.