Skip to content

Commit 7ee0e77

Browse files
mlaroucheandrewrk
authored andcommitted
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 parent 505b9db commit 7ee0e77

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/std/child_process.zig

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 });

0 commit comments

Comments
 (0)