authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-12-16 19:33:06-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-12-16 21:42:39-08:00
log6a1021fb7d14604b4f66b2c992f47eadcc812989
treecbfe12e21ee6c510365eaa42e2cfe716c0091651
parent077b003c50065a8b193dcad793ca5c4474222af6

ChildProcess.spawnWindows: Fix PATH search when the ext is in the command

For example, if the command is specified as `something.exe`, the retry will now try: ``` C:\some\path\something.exe C:\some\path\something.exe.COM C:\some\path\something.exe.EXE C:\some\path\something.exe.BAT ... etc ... ``` whereas before it would only try the versions with an added extension from `PATHEXT`, which would cause the retry to fail on things that it should find.

1 files changed, 13 insertions(+), 3 deletions(-)

lib/std/child_process.zig+13-3
......@@ -995,12 +995,22 @@ pub const ChildProcess = struct {
995995 const path_no_ext = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_name });
996996 defer self.allocator.free(path_no_ext);
997997
998 const path_no_ext_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, path_no_ext);
999 defer self.allocator.free(path_no_ext_w);
1000
1001 if (windowsCreateProcess(path_no_ext_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| {
1002 break :retry;
1003 } else |err| switch (err) {
1004 error.FileNotFound, error.AccessDenied => {},
1005 else => return err,
1006 }
1007
9981008 var ext_it = mem.tokenize(u8, PATHEXT, ";");
9991009 while (ext_it.next()) |app_ext| {
1000 const joined_path = try mem.concat(self.allocator, u8, &[_][]const u8{ path_no_ext, app_ext });
1001 defer self.allocator.free(joined_path);
1010 const ext_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, app_ext);
1011 defer self.allocator.free(ext_w);
10021012
1003 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);
1013 const joined_path_w = try std.mem.concatWithSentinel(self.allocator, u16, &.{ path_no_ext_w, ext_w }, 0);
10041014 defer self.allocator.free(joined_path_w);
10051015
10061016 if (windowsCreateProcess(joined_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| {