| ... | ... | @@ -101,14 +101,50 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, |
| 101 | 101 | #endif |
| 102 | 102 | |
| 103 | 103 | #if defined(ZIG_OS_WINDOWS) |
| 104 | static void os_windows_create_command_line(Buf *command_line, const char *exe, ZigList<const char *> &args) { |
| 105 | buf_resize(command_line, 0); |
| 106 | |
| 107 | buf_append_char(command_line, '\"'); |
| 108 | buf_append_str(command_line, exe); |
| 109 | buf_append_char(command_line, '\"'); |
| 110 | |
| 111 | for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) { |
| 112 | buf_append_str(command_line, " \""); |
| 113 | const char *arg = args.at(arg_i); |
| 114 | size_t arg_len = strlen(arg); |
| 115 | for (size_t c_i = 0; c_i < arg_len; c_i += 1) { |
| 116 | if (arg[c_i] == '\"') { |
| 117 | zig_panic("TODO"); |
| 118 | } |
| 119 | buf_append_char(command_line, arg[c_i]); |
| 120 | } |
| 121 | buf_append_char(command_line, '\"'); |
| 122 | } |
| 123 | } |
| 124 | |
| 104 | 125 | static void os_spawn_process_windows(const char *exe, ZigList<const char *> &args, Termination *term) { |
| 105 | | Buf stderr_buf = BUF_INIT; |
| 106 | | Buf stdout_buf = BUF_INIT; |
| 126 | Buf command_line = BUF_INIT; |
| 127 | os_windows_create_command_line(&command_line, exe, args); |
| 128 | |
| 129 | PROCESS_INFORMATION piProcInfo = {0}; |
| 130 | STARTUPINFO siStartInfo = {0}; |
| 131 | siStartInfo.cb = sizeof(STARTUPINFO); |
| 132 | |
| 133 | BOOL success = CreateProcessA(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, |
| 134 | &siStartInfo, &piProcInfo); |
| 135 | |
| 136 | if (!success) { |
| 137 | zig_panic("CreateProcess failed. exe: %s command_line: %s", exe, buf_ptr(&command_line)); |
| 138 | } |
| 139 | |
| 140 | WaitForSingleObject(piProcInfo.hProcess, INFINITE); |
| 107 | 141 | |
| 108 | | // TODO this is supposed to inherit stdout/stderr instead of capturing it |
| 109 | | os_exec_process(exe, args, term, &stderr_buf, &stdout_buf); |
| 110 | | fwrite(buf_ptr(&stderr_buf), 1, buf_len(&stderr_buf), stderr); |
| 111 | | fwrite(buf_ptr(&stdout_buf), 1, buf_len(&stdout_buf), stdout); |
| 142 | DWORD exit_code; |
| 143 | if (!GetExitCodeProcess(piProcInfo.hProcess, &exit_code)) { |
| 144 | zig_panic("GetExitCodeProcess failed"); |
| 145 | } |
| 146 | term->how = TerminationIdClean; |
| 147 | term->code = exit_code; |
| 112 | 148 | } |
| 113 | 149 | #endif |
| 114 | 150 | |
| ... | ... | @@ -368,25 +404,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args, |
| 368 | 404 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 369 | 405 | { |
| 370 | 406 | Buf command_line = BUF_INIT; |
| 371 | | buf_resize(&command_line, 0); |
| 372 | | |
| 373 | | buf_append_char(&command_line, '\"'); |
| 374 | | buf_append_str(&command_line, exe); |
| 375 | | buf_append_char(&command_line, '\"'); |
| 376 | | |
| 377 | | for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) { |
| 378 | | buf_append_str(&command_line, " \""); |
| 379 | | const char *arg = args.at(arg_i); |
| 380 | | size_t arg_len = strlen(arg); |
| 381 | | for (size_t c_i = 0; c_i < arg_len; c_i += 1) { |
| 382 | | if (arg[c_i] == '\"') { |
| 383 | | zig_panic("TODO"); |
| 384 | | } |
| 385 | | buf_append_char(&command_line, arg[c_i]); |
| 386 | | } |
| 387 | | buf_append_char(&command_line, '\"'); |
| 388 | | } |
| 389 | | |
| 407 | os_windows_create_command_line(&command_line, exe, args); |
| 390 | 408 | |
| 391 | 409 | HANDLE g_hChildStd_IN_Rd = NULL; |
| 392 | 410 | HANDLE g_hChildStd_IN_Wr = NULL; |