From a28ada5e5e5f4ef5d06ce3e7cb34bff736d12ab6 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 20 Oct 2025 08:11:59 +0900 Subject: [PATCH] hal-win-io: fix backtick operator on windows on windows, pipe handles created by _pipe are marked non-inheritable for security by mrb_hal_io_pipe. when spawning child processes via io.popen (used by backtick operator), the child needs to inherit stdin/stdout/stderr handles to communicate with the parent process. before calling createprocess, explicitly set handle_flag_inherit on the stdio handles so child processes can use them. this fixes the backtick operator returning empty strings on windows (msvc and mingw, both 32-bit and 64-bit). Co-authored-by: Claude --- mrbgems/hal-win-io/src/io_hal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mrbgems/hal-win-io/src/io_hal.c b/mrbgems/hal-win-io/src/io_hal.c index 6f2ecacea..9cc3583bd 100644 --- a/mrbgems/hal-win-io/src/io_hal.c +++ b/mrbgems/hal-win-io/src/io_hal.c @@ -439,9 +439,10 @@ mrb_hal_io_spawn_process(mrb_state *mrb, const char *cmd, si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES; - /* Convert file descriptors to handles */ + /* Convert file descriptors to handles and make them inheritable */ if (stdin_fd != -1) { h_stdin = (HANDLE)_get_osfhandle(stdin_fd); + SetHandleInformation(h_stdin, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); si.hStdInput = h_stdin; } else { @@ -450,6 +451,7 @@ mrb_hal_io_spawn_process(mrb_state *mrb, const char *cmd, if (stdout_fd != -1) { h_stdout = (HANDLE)_get_osfhandle(stdout_fd); + SetHandleInformation(h_stdout, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); si.hStdOutput = h_stdout; } else { @@ -458,6 +460,7 @@ mrb_hal_io_spawn_process(mrb_state *mrb, const char *cmd, if (stderr_fd != -1) { h_stderr = (HANDLE)_get_osfhandle(stderr_fd); + SetHandleInformation(h_stderr, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); si.hStdError = h_stderr; } else {