| 119 | } |
| 120 | |
| 121 | int spawnProcess(Process *process, const char *app, char *const *args) { |
| 122 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) |
| 123 | STARTUPINFO si = {0}; |
| 124 | BOOL status; |
| 125 | size_t arglen = 0; |
| 126 | size_t argIdx = 0; |
| 127 | std::string arg_string; |
| 128 | memset(process, 0, sizeof(*process)); |
| 129 | |
| 130 | while (*args) { |
| 131 | arg_string.append(*args).append(1, ' '); |
| 132 | args++; |
| 133 | } |
| 134 | |
| 135 | status = CreateProcess(app, LPSTR(arg_string.c_str()), NULL, NULL, FALSE, 0, |
| 136 | NULL, NULL, &si, process); |
| 137 | |
| 138 | return status ? 0 : GetLastError(); |
| 139 | #else |
| 140 | *process = fork(); |
| 141 | if (*process == 0) { |
| 142 | if (0 > execvp(app, args)) { |
| 143 | return errno; |
| 144 | } |
| 145 | } else if (*process < 0) { |
| 146 | return errno; |
| 147 | } |
| 148 | return 0; |
| 149 | #endif |
| 150 | } |
| 151 | |
| 152 | int waitProcess(Process *process) { |
| 153 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) |