authorgravatar for michael.larouche@gmail.comMichaël Larouche <michael.larouche@gmail.com> 2020-01-10 19:25:26-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-14 15:12:30-05:00
log7ee0e779af1f9b457afee259a4137e928e9627f8
treedac82e99efb3f5c90d0f11eccca297d836ca95f1
parent505b9db9090c7decba68c7882b1330f48aff0c10

Fix std.child_process.ChildProcess.spawnWindow when looking in PATH environment variable, it applied cwd+app_name instead of just using the app_name


1 files changed, 7 insertions(+), 5 deletions(-)

lib/std/child_process.zig+7-5
......@@ -592,7 +592,7 @@ pub const ChildProcess = struct {
592592
593593 // the cwd set in ChildProcess is in effect when choosing the executable path
594594 // to match posix semantics
595 const app_name = x: {
595 const app_path = x: {
596596 if (self.cwd) |cwd| {
597597 const resolved = try fs.path.resolve(self.allocator, &[_][]const u8{ cwd, self.argv[0] });
598598 defer self.allocator.free(resolved);
......@@ -601,15 +601,15 @@ pub const ChildProcess = struct {
601601 break :x try cstr.addNullByte(self.allocator, self.argv[0]);
602602 }
603603 };
604 defer self.allocator.free(app_name);
604 defer self.allocator.free(app_path);
605605
606 const app_name_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, app_name);
607 defer self.allocator.free(app_name_w);
606 const app_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, app_path);
607 defer self.allocator.free(app_path_w);
608608
609609 const cmd_line_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, cmd_line);
610610 defer self.allocator.free(cmd_line_w);
611611
612 windowsCreateProcess(app_name_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
612 windowsCreateProcess(app_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
613613 if (no_path_err != error.FileNotFound) return no_path_err;
614614
615615 var free_path = true;
......@@ -632,6 +632,8 @@ pub const ChildProcess = struct {
632632 };
633633 defer if (free_path_ext) self.allocator.free(PATHEXT);
634634
635 const app_name = self.argv[0];
636
635637 var it = mem.tokenize(PATH, ";");
636638 retry: while (it.next()) |search_path| {
637639 const path_no_ext = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_name });