=> 6ac8385d39bf7396589a3926d0d22f0958fd28a3
[1mdiff --git a/src/platform/win32/process.c b/src/platform/win32/process.c[m [1mindex df1b5a9..36c8978 100644[m [1m--- a/src/platform/win32/process.c[m [1m+++ b/src/platform/win32/process.c[m [36m@@ -44,6 +44,7 @@[m [mstruct Impl_Process {[m iPipe pin;[m iPipe pout;[m iPipe perr;[m [32m+[m[32m iBlock *bufOut;[m PROCESS_INFORMATION procInfo;[m STARTUPINFOW startInfo;[m int exitStatus;[m [36m@@ -60,6 +61,7 @@[m [mvoid init_Process(iProcess *d) {[m init_Pipe(&d->pin);[m init_Pipe(&d->pout);[m init_Pipe(&d->perr);[m [32m+[m[32m d->bufOut = new_Block(0);[m iZap(d->procInfo);[m d->startInfo = (STARTUPINFOW){[m .cb = sizeof(d->startInfo),[m [36m@@ -93,6 +95,7 @@[m [mvoid deinit_Process(iProcess *d) {[m deinit_Pipe(&d->pin);[m deinit_Pipe(&d->pout);[m deinit_Pipe(&d->perr);[m [32m+[m[32m delete_Block(d->bufOut);[m }[m [m void setArguments_Process(iProcess *d, const iStringList *args) {[m [36m@@ -132,24 +135,24 @@[m [miBool start_Process(iProcess *d) {[m delete_String(arg);[m }[m }[m [31m- printf("cmdline: %s\n", cstr_String(cmdLine));[m /* The environment. */[m if (!isEmpty_StringList(d->envMods)) {[m [31m- //iBlock *env = collect_Block(new_Block(0));[m [31m- /* TODO: Compose the new environment strings */[m [31m-#if 0[m [31m- for (const char *envList = GetEnvironmentStringsA(); *envList; ) {[m [31m- size_t len = strlen(envList);[m [31m- pushBack_Array(env, e);[m [32m+[m[32m iBlock *envUtf16 = collect_Block(new_Block(0));[m [32m+[m[32m for (const wchar_t *e = GetEnvironmentStringsW(); *e; ) {[m [32m+[m[32m size_t len = wcslen(e);[m [32m+[m[32m appendData_Block(envUtf16, e, (len + 1) * 2);[m [32m+[m[32m e += len + 1;[m }[m iConstForEach(StringList, e, d->envMods) {[m [31m- pushBack_Array(env, &(const char *){ cstr_String(e.value) });[m [32m+[m[32m iBlock *wide = toUtf16_String(e.value);[m [32m+[m[32m append_Block(envUtf16, wide);[m [32m+[m[32m delete_Block(wide);[m [32m+[m[32m appendData_Block(envUtf16, &(wchar_t){ 0 }, 2);[m }[m [31m- pushBack_Array(env, &(const char *){ NULL });[m [31m- envs = (LPVOID) data_Array(env);[m [31m-#endif[m [32m+[m[32m appendData_Block(envUtf16, (wchar_t[]){ 0, 0 }, 4);[m [32m+[m[32m envs = (LPVOID) data_Block(envUtf16);[m }[m [31m- DWORD creationFlags = 0;[m [32m+[m[32m DWORD creationFlags = CREATE_UNICODE_ENVIRONMENT;[m BOOL ok = CreateProcessW([m NULL,[m (LPWSTR) toWide_CStr_(cstr_String(cmdLine)),[m [36m@@ -201,10 +204,14 @@[m [mint exitStatus_Process(const iProcess *d) {[m [m void waitForFinished_Process(iProcess *d) {[m if (d->pid) {[m [32m+[m[32m iBlock *out = readOutputUntilClosed_Process(d);[m [32m+[m[32m append_Block(d->bufOut, out);[m [32m+[m[32m delete_Block(out);[m DWORD exitCode = 0;[m [31m- WaitForSingleObject(d->procInfo.hProcess, INFINITE);[m [31m- GetExitCodeProcess(d->procInfo.hProcess, &exitCode);[m [31m- d->exitStatus = exitCode;[m [32m+[m[32m BOOL ok = GetExitCodeProcess(d->procInfo.hProcess, &exitCode);[m [32m+[m[32m if (ok) {[m [32m+[m[32m d->exitStatus = exitCode;[m [32m+[m[32m }[m d->pid = 0;[m }[m }[m [36m@@ -233,7 +240,9 @@[m [mstatic iBlock *readFromPipe_(HANDLE pipe, iBlock *readChars) {[m }[m [m iBlock *readOutput_Process(iProcess *d) {[m [31m- return readFromPipe_(output_Pipe(&d->pout), new_Block(0));[m [32m+[m[32m iBlock *buf = copy_Block(d->bufOut);[m [32m+[m[32m clear_Block(d->bufOut);[m [32m+[m[32m return readFromPipe_(output_Pipe(&d->pout), buf);[m }[m [m iBlock *readError_Process(iProcess *d) {[m [36m@@ -246,14 +255,13 @@[m [mvoid kill_Process(iProcess *d) {[m }[m }[m [m [31m-iBlock *readOutputUntilClosed_Process(iProcess *d) { [m [31m- iBlock *output = new_Block(0);[m [32m+[m[32miBlock *readOutputUntilClosed_Process(iProcess *d) {[m [32m+[m[32m iBlock *output = copy_Block(d->bufOut);[m [32m+[m[32m clear_Block(d->bufOut);[m if (!d->pid) {[m return output;[m }[m HANDLE fd = output_Pipe(&d->pout);[m [31m- //DWORD mode = PIPE_WAIT;[m [31m- //SetNamedPipeHandleState(fd, &mode, NULL, NULL); /* blocking mode */[m CloseHandle(input_Pipe(&d->pin)); /* no more input */[m for (;;) {[m char buf[0x20000];[m [1mdiff --git a/tests/t_process.c b/tests/t_process.c[m [1mindex 44a9c67..e4ce122 100644[m [1m--- a/tests/t_process.c[m [1m+++ b/tests/t_process.c[m [36m@@ -30,6 +30,9 @@[m [mSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[m #include[m #include [m [m [32m+[m[32m#define TEST_MULTITHREAD 0[m [32m+[m [32m+[m[32m#if TEST_MULTITHREAD[m iMutex mtx_; /* avoid pipe issues */[m [m static iThreadResult run_(iThread *d) {[m [36m@@ -64,10 +67,39 @@[m [mstatic iThreadResult run_(iThread *d) {[m iRelease(args);[m return 0;[m }[m [32m+[m[32m#endif[m [m int main(int argc, char *argv[]) {[m iUnused(argc, argv); [m init_Foundation();[m [32m+[m[32m /* Test GUI launch. */ {[m [32m+[m[32m iProcess *proc = new_Process();[m [32m+[m[32m setArguments_Process(proc, iClob(newStringsCStr_StringList("c:\\windows\\notepad.exe", NULL)));[m [32m+[m[32m //start_Process(proc);[m [32m+[m[32m waitForFinished_Process(proc);[m [32m+[m[32m iRelease(proc);[m [32m+[m[32m }[m [32m+[m[32m /* Test arguments and environment. */ {[m [32m+[m[32m iProcess *proc = new_Process();[m [32m+[m[32m setArguments_Process(proc,[m [32m+[m[32m iClob(newStringsCStr_StringList([m [32m+[m[32m "c:\\msys64\\usr\\bin\\printenv.exe", NULL)));[m [32m+[m[32m setEnvironment_Process(proc,[m [32m+[m[32m collect_StringList(newStringsCStr_StringList([m [32m+[m[32m "TESTVALUE=Keränen", "OTHER=something with space", NULL)));[m [32m+[m[32m if (start_Process(proc))[m [32m+[m[32m {[m [32m+[m[32m waitForFinished_Process(proc);[m [32m+[m[32m iBlock *out = collect_Block(readOutput_Process(proc));[m [32m+[m[32m iString *outs = collect_String(newBlock_String(out));[m [32m+[m[32m printf("Child environment:\n%s\n", cstrLocal_String(outs));[m [32m+[m[32m }[m [32m+[m[32m else {[m [32m+[m[32m printf("Failed to start\n");[m [32m+[m[32m }[m [32m+[m[32m iRelease(proc);[m [32m+[m[32m }[m [32m+[m[32m#if TEST_MULTITHREAD[m init_Mutex(&mtx_);[m iThread *thds[8];[m iForIndices(i, thds) {[m [36m@@ -77,7 +109,8 @@[m [mint main(int argc, char *argv[]) {[m iForIndices(i, thds) {[m join_Thread(thds[i]);[m iRelease(thds[i]);[m [31m- } [m [32m+[m[32m }[m [32m+[m[32m#endif[m deinit_Foundation();[m return 0;[m }[m
text/gemini; charset=utf-8
This content has been proxied by September (ba2dc).