Add rb_w32_uspawn_process

This commit is contained in:
Nobuyoshi Nakada 2023-08-05 22:10:49 +09:00
parent 6bb4c9de09
commit 0f64290704
2 changed files with 29 additions and 5 deletions

View File

@ -47,4 +47,7 @@ int fchmod(int fd, int mode);
UINT rb_w32_filecp(void); UINT rb_w32_filecp(void);
WCHAR *rb_w32_home_dir(void); WCHAR *rb_w32_home_dir(void);
rb_pid_t rb_w32_uspawn_process(int mode, const char *prog, char *const *argv,
int in_fd, int out_fd, int err_fd, DWORD flags);
#endif /* RUBY_WIN32_FILE_H */ #endif /* RUBY_WIN32_FILE_H */

View File

@ -1537,7 +1537,8 @@ rb_w32_uspawn(int mode, const char *cmd, const char *prog)
/* License: Artistic or GPL */ /* License: Artistic or GPL */
static rb_pid_t static rb_pid_t
w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags, UINT cp) w32_spawn_process(int mode, const char *prog, char *const *argv,
int in_fd, int out_fd, int err_fd, DWORD flags, UINT cp)
{ {
int c_switch = 0; int c_switch = 0;
size_t len; size_t len;
@ -1548,9 +1549,20 @@ w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags, UIN
int e = 0; int e = 0;
rb_pid_t ret = -1; rb_pid_t ret = -1;
VALUE v = 0; VALUE v = 0;
HANDLE in_handle = NULL, out_handle = NULL, err_handle = NULL;
if (check_spawn_mode(mode)) return -1; if (check_spawn_mode(mode)) return -1;
if (in_fd >= 0) {
in_handle = (HANDLE)rb_w32_get_osfhandle(in_fd);
}
if (out_fd >= 0) {
out_handle = (HANDLE)rb_w32_get_osfhandle(out_fd);
}
if (err_fd >= 0) {
err_handle = (HANDLE)rb_w32_get_osfhandle(err_fd);
}
if (!prog) prog = argv[0]; if (!prog) prog = argv[0];
if ((shell = w32_getenv("COMSPEC", cp)) && if ((shell = w32_getenv("COMSPEC", cp)) &&
internal_cmd_match(prog, tmpnt = !is_command_com(shell))) { internal_cmd_match(prog, tmpnt = !is_command_com(shell))) {
@ -1598,7 +1610,7 @@ w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags, UIN
if (!e) { if (!e) {
struct ChildRecord *child = FindFreeChildSlot(); struct ChildRecord *child = FindFreeChildSlot();
if (CreateChild(child, wcmd, wprog, NULL, NULL, NULL, flags)) { if (CreateChild(child, wcmd, wprog, in_handle, out_handle, err_handle, flags)) {
ret = child_result(child, mode); ret = child_result(child, mode);
} }
} }
@ -1613,21 +1625,21 @@ rb_pid_t
rb_w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags) rb_w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags)
{ {
/* assume ACP */ /* assume ACP */
return w32_aspawn_flags(mode, prog, argv, flags, filecp()); return w32_spawn_process(mode, prog, argv, -1, -1, -1, flags, filecp());
} }
/* License: Ruby's */ /* License: Ruby's */
rb_pid_t rb_pid_t
rb_w32_uaspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags) rb_w32_uaspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags)
{ {
return w32_aspawn_flags(mode, prog, argv, flags, CP_UTF8); return w32_spawn_process(mode, prog, argv, -1, -1, -1, flags, CP_UTF8);
} }
/* License: Ruby's */ /* License: Ruby's */
rb_pid_t rb_pid_t
rb_w32_aspawn(int mode, const char *prog, char *const *argv) rb_w32_aspawn(int mode, const char *prog, char *const *argv)
{ {
return w32_aspawn_flags(mode, prog, argv, 0, filecp()); return w32_spawn_process(mode, prog, argv, -1, -1, -1, 0, filecp());
} }
/* License: Ruby's */ /* License: Ruby's */
@ -1637,6 +1649,15 @@ rb_w32_uaspawn(int mode, const char *prog, char *const *argv)
return rb_w32_uaspawn_flags(mode, prog, argv, 0); return rb_w32_uaspawn_flags(mode, prog, argv, 0);
} }
/* License: Ruby's */
rb_pid_t
rb_w32_uspawn_process(int mode, const char *prog, char *const *argv,
int in_fd, int out_fd, int err_fd, DWORD flags)
{
return w32_spawn_process(mode, prog, argv, in_fd, out_fd, err_fd,
flags, CP_UTF8);
}
/* License: Artistic or GPL */ /* License: Artistic or GPL */
typedef struct _NtCmdLineElement { typedef struct _NtCmdLineElement {
struct _NtCmdLineElement *next; struct _NtCmdLineElement *next;