mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user