*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Tue, 08 Nov 2016 15:50:54 +0100
changeset 20896 c88fbd0cb367
parent 20895 0210e874e38b
child 20897 49ffdb7d9c18
*** empty log message ***
Win32OperatingSystem.st
--- a/Win32OperatingSystem.st	Tue Nov 08 14:48:08 2016 +0100
+++ b/Win32OperatingSystem.st	Tue Nov 08 15:50:54 2016 +0100
@@ -292,7 +292,7 @@
 #  define _FCNTL_H_INCLUDED_
 # endif
 
-// # define PROCESSDEBUGWIN32
+# define PROCESSDEBUGWIN32
 // # define PROCESS1DEBUGWIN32
 // # define PROCESS2DEBUGWIN32
 // # define PROCESSDEBUG_CHILDPROCESSWAIT
@@ -551,6 +551,10 @@
 
 #endif /* BORLAND */
 
+#ifdef PROCESSDEBUGWIN32
+static int flag_PROCESSDEBUGWIN32 = 0;
+#endif
+
 %}
 ! !
 
@@ -899,6 +903,16 @@
 "
 ! !
 
+!Win32OperatingSystem class methodsFor:'debugging'!
+
+verbose:aBoolean
+%{
+#ifdef PROCESSDEBUGWIN32
+    flag_PROCESSDEBUGWIN32 = (aBoolean == true);
+#endif
+%}
+! !
+
 !Win32OperatingSystem class methodsFor:'initialization'!
 
 coInitialize
@@ -3662,64 +3676,64 @@
 !
 
 exec:aCommandPath withArguments:argString environment:environment fileDescriptors:fdArray fork:doFork
-        newPgrp:newPgrp inDirectory:aDirectory
-        showWindow:showWindowBooleanOrNil
+	newPgrp:newPgrp inDirectory:aDirectory
+	showWindow:showWindowBooleanOrNil
 
     "Internal lowLevel entry for combined fork & exec for WIN32
 
      If fork is false (chain a command):
-         execute the OS command specified by the argument, aCommandPath, with
-         arguments in argArray (no arguments, if nil).
-         If successful, this method does not return and smalltalk is gone.
-         If not successful, it does return.
-         Normal use is with forkForCommand.
+	 execute the OS command specified by the argument, aCommandPath, with
+	 arguments in argArray (no arguments, if nil).
+	 If successful, this method does not return and smalltalk is gone.
+	 If not successful, it does return.
+	 Normal use is with forkForCommand.
 
      If fork is true (subprocess command execution):
-        fork a child to do the above.
-        The Win32ProcessHandle of the child process is returned; nil if the fork failed.
+	fork a child to do the above.
+	The Win32ProcessHandle of the child process is returned; nil if the fork failed.
 
      fdArray contains the filedescriptors, to be used for the child (if fork is true).
-        fdArray[1] = 15 -> use fd 15 as stdin.
-        If an element of the array is set to nil, the corresponding filedescriptor
-        will be closed for the child.
-        fdArray[0] == StdIn for child
-        fdArray[1] == StdOut for child
-        fdArray[2] == StdErr for child
+	fdArray[1] = 15 -> use fd 15 as stdin.
+	If an element of the array is set to nil, the corresponding filedescriptor
+	will be closed for the child.
+	fdArray[0] == StdIn for child
+	fdArray[1] == StdOut for child
+	fdArray[2] == StdErr for child
 
      NOTE that in WIN32 the fds are HANDLES.
 
      If newPgrp is true, the subprocess will be established in a new process group.
-        The processgroup will be equal to id.
-        newPgrp is not used on WIN32 and VMS systems.
+	The processgroup will be equal to id.
+	newPgrp is not used on WIN32 and VMS systems.
 
      showWindowOrBoolean may be:
-        true  - a window is shown on start of the command
-        false - the command window is hidden
-        nil   - the nCmdShown parameter of the commans's winmain function determins,
-                if a window is shown.
-        #default
-              - same as nil
+	true  - a window is shown on start of the command
+	false - the command window is hidden
+	nil   - the nCmdShown parameter of the commans's winmain function determins,
+		if a window is shown.
+	#default
+	      - same as nil
     "
 
     |dirPath rslt|
 
     aDirectory notNil ifTrue:[
-        dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory.
-        (dirPath endsWith:':') ifTrue:[
-            dirPath := dirPath , '\'.
-        ].
+	dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory.
+	(dirPath endsWith:':') ifTrue:[
+	    dirPath := dirPath , '\'.
+	].
     ].
 
     rslt := self
-        primExec:aCommandPath
-        commandLine:argString
-        fileDescriptors:fdArray
-        fork:doFork
-        newPgrp:newPgrp
-        inPath:dirPath
-        createFlags:nil
-        inheritHandles:true
-        showWindow:showWindowBooleanOrNil.
+	primExec:aCommandPath
+	commandLine:argString
+	fileDescriptors:fdArray
+	fork:doFork
+	newPgrp:newPgrp
+	inPath:dirPath
+	createFlags:nil
+	inheritHandles:true
+	showWindow:showWindowBooleanOrNil.
 
 "/ 'created ' print. cmdLine print. ' -> ' print. rslt printCR.
     ^ rslt
@@ -3752,9 +3766,13 @@
 		if (GetExitCodeProcess(handle,&endStatus)) {
 		    status = endStatus;
 #ifdef PROCESSDEBUGWIN32
-		    console_fprintf(stderr, "getexitcode status = %d\n",status);
+		    if (flag_PROCESSDEBUGWIN32) {
+			console_fprintf(stderr, "getexitcode status = %d\n",status);
+		    }
 		} else {
-		    console_fprintf(stderr, "getexitcode failed.\n");
+		    if (flag_PROCESSDEBUGWIN32) {
+			console_fprintf(stderr, "getexitcode failed.\n");
+		    }
 #endif
 		}
 	    }
@@ -3840,17 +3858,17 @@
 !
 
 primExec:commandPath commandLine:commandLine fileDescriptors:fdArray fork:doFork newPgrp:newPgrp
-        inPath:dirName createFlags:flagsOrNil inheritHandles:inheritHandles
-        showWindow:showWindowBooleanOrNil
+	inPath:dirName createFlags:flagsOrNil inheritHandles:inheritHandles
+	showWindow:showWindowBooleanOrNil
     "Internal lowLevel entry for combined fork & exec for WIN32
 
      showWindowBooleanOrNil may be:
-        true  - a window is shown on start of the command
-        false - the command window is hidden
-        nil   - the nCmdShown parameter of the commans's winmain function determins,
-                if a window is shown.
-        #default
-              - same as nil
+	true  - a window is shown on start of the command
+	false - the command window is hidden
+	nil   - the nCmdShown parameter of the commans's winmain function determins,
+		if a window is shown.
+	#default
+	      - same as nil
     "
 
     |handle commandPathUni16 commandLineUni16 dirNameUni16|
@@ -3862,13 +3880,13 @@
     dirNameUni16 := dirName.
 
     commandPathUni16 notNil ifTrue:[
-        commandPathUni16 := commandPathUni16 asUnicode16String.
+	commandPathUni16 := commandPathUni16 asUnicode16String.
     ].
     commandLineUni16 notNil ifTrue:[
-        commandLineUni16 := commandLineUni16 asUnicode16String.
+	commandLineUni16 := commandLineUni16 asUnicode16String.
     ].
     dirNameUni16 notNil ifTrue:[
-        dirNameUni16 := dirNameUni16 asUnicode16String.
+	dirNameUni16 := dirNameUni16 asUnicode16String.
     ].
 
 
@@ -3906,280 +3924,295 @@
     SECURITY_DESCRIPTOR securityDescriptor;
 
     if ((__isUnicode16String(commandPathUni16) || (commandPathUni16 == nil)) && __isUnicode16String(commandLineUni16)) {
-        HANDLE stdinHandle = NULL;
-        HANDLE stdoutHandle = NULL;
-        HANDLE stderrHandle = NULL;
-        int mustClose_stdinHandle = 0;
-        int mustClose_stdoutHandle = 0;
-        int mustClose_stderrHandle = 0;
-
-        /*
-         * terminate the multi byte strings
-         */
-        // #commandPathUni16
-        if (commandPathUni16 != nil) {
-            l = __unicode16StringSize(commandPathUni16);
-            if (l >= 4096) { // >= need 1 space for terminator
-                #ifdef PROCESSDEBUGWIN32
-                console_fprintf(stderr, "argument #commandPathUni16 is to long\n");
-                #endif
-                RETURN(nil);
-            }
-            for (i = 0; i < l; i++) {
-                cmdPathW[i] = __unicode16StringVal(commandPathUni16)[i];
-            }
-            cmdPathW[i] = 0; // set terminator
-            cmdPathWP = &cmdPathW[0];
-        }
-
-        // commandLineUni16
-        l = __unicode16StringSize(commandLineUni16);
-        if (l >= 4096) { // >= need 1 space for terminator
-            #ifdef PROCESSDEBUGWIN32
-            console_fprintf(stderr, "argument #commandLineUni16 is to long\n");
-            #endif
-            RETURN(nil);
-        }
-        for (i = 0; i < l; i++) {
-            cmdLineW[i] = __unicode16StringVal(commandLineUni16)[i];
-        }
-        cmdLineW[i] = 0; // set terminator
-        cmdLineWP = &cmdLineW[0];
-
-        // #dirNameUni16
-        if (__isUnicode16String(dirNameUni16)) {
-            l = __unicode16StringSize(dirNameUni16);
-            if (l >= 4096) { // >= need 1 space for terminator
-                #ifdef PROCESSDEBUGWIN32
-                console_fprintf(stderr, "argument #dirNameUni16 is to long\n");
-                #endif
-                RETURN(nil);
-            }
-            for (i = 0; i < l; i++) {
-                dirNameW[i] = __unicode16StringVal(dirNameUni16)[i];
-            }
-            dirNameW[i] = 0; // set terminator
-            dirNameWP = &dirNameW[0];
-        }
-
-        /*
-         * create descriptors as req'd
-         */
-        memset(&securityAttributes, 0, sizeof(securityAttributes));
-        securityAttributes.nLength = sizeof(securityAttributes);
-        securityAttributes.bInheritHandle = (inheritHandles == true) ? TRUE : FALSE;
-
-        InitializeSecurityDescriptor(&securityDescriptor, SECURITY_DESCRIPTOR_REVISION);
-        SetSecurityDescriptorDacl(&securityDescriptor, -1, 0, 0);
-
-        securityAttributes.lpSecurityDescriptor = &securityDescriptor;
-        memset(&lppiProcInfo, 0, sizeof (lppiProcInfo));
-
-        memset(&lpsiStartInfo, 0, sizeof(lpsiStartInfo));
-        lpsiStartInfo.cb                = sizeof(lpsiStartInfo);
-        lpsiStartInfo.lpReserved        = NULL;
-        lpsiStartInfo.lpDesktop         = NULL;
-        lpsiStartInfo.lpTitle           = NULL;
-        lpsiStartInfo.dwX               = 0;
-        lpsiStartInfo.dwY               = 0;
-        lpsiStartInfo.dwXSize           = 100;
-        lpsiStartInfo.dwYSize           = 100;
-        lpsiStartInfo.dwXCountChars     = 0;
-        lpsiStartInfo.dwYCountChars     = 0;
-        lpsiStartInfo.dwFillAttribute   = 0;
-        lpsiStartInfo.dwFlags           = STARTF_USESTDHANDLES /*| STARTF_USEPOSITION*/;
-        if ((showWindowBooleanOrNil != nil) && (showWindowBooleanOrNil != @symbol(default))) {
-            lpsiStartInfo.dwFlags |= STARTF_USESHOWWINDOW;
-            lpsiStartInfo.wShowWindow = showWindowBooleanOrNil == true ? SW_SHOWNORMAL : SW_HIDE;
-        }
-        lpsiStartInfo.cbReserved2       = 0;
-        lpsiStartInfo.lpReserved2       = NULL;
-        lpsiStartInfo.hStdInput         = NULL;
-        lpsiStartInfo.hStdOutput        = NULL;
-        lpsiStartInfo.hStdError         = NULL;
-
-        /*
-         * set create process flags
-         * if the flags arg is nil, use common defaults;
-         * if non-nil, it must be a positive integer containing the fdwCreate bits.
-         */
-        if (flagsOrNil != nil) {
-            fdwCreate = __longIntVal(flagsOrNil);
-        } else {
-            fdwCreate = CREATE_NEW_CONSOLE; //|IDLE_PRIORITY_CLASS; // DETACHED_PROCESS; // NORMAL_PRIORITY_CLASS ;
-            if (newPgrp == true) {
-                fdwCreate |= CREATE_NEW_PROCESS_GROUP;
-            }
-            fdwCreate |= CREATE_DEFAULT_ERROR_MODE;
-        }
-
-        if (fdArray == nil) {
-            stdinHandle  = (HANDLE) _get_osfhandle (0);
-            stdoutHandle = (HANDLE) _get_osfhandle (1);
-            stderrHandle  = (HANDLE) _get_osfhandle (2);
-        } else if (__isArrayLike(fdArray) && (__arraySize(fdArray) >= 3)) {
-            if (__ArrayInstPtr(fdArray)->a_element[0] != nil) {
-                if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[0])) {
-                    stdinHandle = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[0]);
-                } else {
-                    stdinHandle = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[0]));
-                }
-            }
-            if (__ArrayInstPtr(fdArray)->a_element[1] != nil) {
-                if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[1])) {
-                    stdoutHandle = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[1]);
-                } else {
-                    stdoutHandle = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[1]));
-                }
-            }
-            if (__ArrayInstPtr(fdArray)->a_element[2] != nil) {
-                if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[2])) {
-                    stderrHandle  = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[2]);
-                } else {
-                    stderrHandle = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[2]));
-                }
-            }
-        } else {
-            console_fprintf(stderr, "Win32OS [warning]: bad fd arg in createProcess\n");
-        }
+	HANDLE stdinHandle = NULL;
+	HANDLE stdoutHandle = NULL;
+	HANDLE stderrHandle = NULL;
+	int mustClose_stdinHandle = 0;
+	int mustClose_stdoutHandle = 0;
+	int mustClose_stderrHandle = 0;
+
+	/*
+	 * terminate the multi byte strings
+	 */
+	// #commandPathUni16
+	if (commandPathUni16 != nil) {
+	    l = __unicode16StringSize(commandPathUni16);
+	    if (l >= 4096) { // >= need 1 space for terminator
+# ifdef PROCESSDEBUGWIN32
+		if (flag_PROCESSDEBUGWIN32) {
+		    console_fprintf(stderr, "argument #commandPathUni16 is to long\n");
+		}
+# endif
+		RETURN(nil);
+	    }
+	    for (i = 0; i < l; i++) {
+		cmdPathW[i] = __unicode16StringVal(commandPathUni16)[i];
+	    }
+	    cmdPathW[i] = 0; // set terminator
+	    cmdPathWP = &cmdPathW[0];
+	}
+
+	// commandLineUni16
+	l = __unicode16StringSize(commandLineUni16);
+	if (l >= 4096) { // >= need 1 space for terminator
+# ifdef PROCESSDEBUGWIN32
+	    if (flag_PROCESSDEBUGWIN32) {
+		console_fprintf(stderr, "argument #commandLineUni16 is to long\n");
+	    }
+# endif
+	    RETURN(nil);
+	}
+	for (i = 0; i < l; i++) {
+	    cmdLineW[i] = __unicode16StringVal(commandLineUni16)[i];
+	}
+	cmdLineW[i] = 0; // set terminator
+	cmdLineWP = &cmdLineW[0];
+
+	// #dirNameUni16
+	if (__isUnicode16String(dirNameUni16)) {
+	    l = __unicode16StringSize(dirNameUni16);
+	    if (l >= 4096) { // >= need 1 space for terminator
+# ifdef PROCESSDEBUGWIN32
+		if (flag_PROCESSDEBUGWIN32) {
+		    console_fprintf(stderr, "argument #dirNameUni16 is to long\n");
+		}
+# endif
+		RETURN(nil);
+	    }
+	    for (i = 0; i < l; i++) {
+		dirNameW[i] = __unicode16StringVal(dirNameUni16)[i];
+	    }
+	    dirNameW[i] = 0; // set terminator
+	    dirNameWP = &dirNameW[0];
+	}
+
+	/*
+	 * create descriptors as req'd
+	 */
+	memset(&securityAttributes, 0, sizeof(securityAttributes));
+	securityAttributes.nLength = sizeof(securityAttributes);
+	securityAttributes.bInheritHandle = (inheritHandles == true) ? TRUE : FALSE;
+
+	InitializeSecurityDescriptor(&securityDescriptor, SECURITY_DESCRIPTOR_REVISION);
+	SetSecurityDescriptorDacl(&securityDescriptor, -1, 0, 0);
+
+	securityAttributes.lpSecurityDescriptor = &securityDescriptor;
+
+	memset(&lpsiStartInfo, 0, sizeof(lpsiStartInfo));
+	lpsiStartInfo.cb                = sizeof(lpsiStartInfo);
+	lpsiStartInfo.lpReserved        = NULL;
+	lpsiStartInfo.lpDesktop         = NULL;
+	lpsiStartInfo.lpTitle           = NULL;
+	lpsiStartInfo.dwX               = 0;
+	lpsiStartInfo.dwY               = 0;
+	lpsiStartInfo.dwXSize           = 100;
+	lpsiStartInfo.dwYSize           = 100;
+	lpsiStartInfo.dwXCountChars     = 0;
+	lpsiStartInfo.dwYCountChars     = 0;
+	lpsiStartInfo.dwFillAttribute   = 0;
+	lpsiStartInfo.dwFlags           = STARTF_USESTDHANDLES /*| STARTF_USEPOSITION*/;
+	if ((showWindowBooleanOrNil != nil) && (showWindowBooleanOrNil != @symbol(default))) {
+	    lpsiStartInfo.dwFlags |= STARTF_USESHOWWINDOW;
+	    lpsiStartInfo.wShowWindow = showWindowBooleanOrNil == true ? SW_SHOWNORMAL : SW_HIDE;
+	}
+	lpsiStartInfo.cbReserved2       = 0;
+	lpsiStartInfo.lpReserved2       = NULL;
+	lpsiStartInfo.hStdInput         = NULL;
+	lpsiStartInfo.hStdOutput        = NULL;
+	lpsiStartInfo.hStdError         = NULL;
+
+	/*
+	 * set create process flags
+	 * if the flags arg is nil, use common defaults;
+	 * if non-nil, it must be a positive integer containing the fdwCreate bits.
+	 */
+	if (flagsOrNil != nil) {
+	    fdwCreate = __longIntVal(flagsOrNil);
+	} else {
+	    fdwCreate = CREATE_NEW_CONSOLE; //|IDLE_PRIORITY_CLASS; // DETACHED_PROCESS; // NORMAL_PRIORITY_CLASS ;
+	    if (newPgrp == true) {
+		fdwCreate |= CREATE_NEW_PROCESS_GROUP;
+	    }
+	    fdwCreate |= CREATE_DEFAULT_ERROR_MODE;
+	}
+
+	if (fdArray == nil) {
+	    stdinHandle  = (HANDLE) _get_osfhandle (0);
+	    stdoutHandle = (HANDLE) _get_osfhandle (1);
+	    stderrHandle  = (HANDLE) _get_osfhandle (2);
+	} else if (__isArrayLike(fdArray) && (__arraySize(fdArray) >= 3)) {
+	    if (__ArrayInstPtr(fdArray)->a_element[0] != nil) {
+		if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[0])) {
+		    stdinHandle = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[0]);
+		} else {
+		    stdinHandle = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[0]));
+		}
+	    }
+	    if (__ArrayInstPtr(fdArray)->a_element[1] != nil) {
+		if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[1])) {
+		    stdoutHandle = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[1]);
+		} else {
+		    stdoutHandle = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[1]));
+		}
+	    }
+	    if (__ArrayInstPtr(fdArray)->a_element[2] != nil) {
+		if (__isExternalAddressLike(__ArrayInstPtr(fdArray)->a_element[2])) {
+		    stderrHandle  = _HANDLEVal(__ArrayInstPtr(fdArray)->a_element[2]);
+		} else {
+		    stderrHandle = (HANDLE) _get_osfhandle (__intVal(__ArrayInstPtr(fdArray)->a_element[2]));
+		}
+	    }
+	} else {
+	    console_fprintf(stderr, "Win32OS [warning]: bad fd arg in createProcess\n");
+	}
 
 #if defined(PROCESSDEBUGWIN32)
-        console_fprintf(stderr, "stdin %x\n", stdinHandle);
-        console_fprintf(stderr, "stdout %x\n", stdoutHandle);
-        console_fprintf(stderr, "stderr %x\n", stderrHandle);
-#endif
-
-        {
-            HANDLE childHandle;
-            int sameHandle = (stdoutHandle == stderrHandle);
-
-            // these MUST be inheritable!
-            if (stdinHandle) {
+	if (flag_PROCESSDEBUGWIN32) {
+	    console_fprintf(stderr, "stdin %x\n", stdinHandle);
+	    console_fprintf(stderr, "stdout %x\n", stdoutHandle);
+	    console_fprintf(stderr, "stderr %x\n", stderrHandle);
+	}
+#endif
+
+	{
+	    HANDLE childHandle;
+	    int sameHandle = (stdoutHandle == stderrHandle);
+
+	    // these MUST be inheritable!
+	    if (stdinHandle) {
 #if 0
-                if (SetHandleInformation(stdinHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
-                    // good
-                } else {
-                    console_fprintf(stderr, "Win32OS [warning]: SetHandleInformation failed in createProcess\n");
-                }
-#else
-                if (DuplicateHandle(GetCurrentProcess(), stdinHandle, GetCurrentProcess(),
-                                      &childHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
-                    stdinHandle = childHandle;
-                    mustClose_stdinHandle = 1;
-                } else {
-                    console_fprintf(stderr, "Win32OS [warning]: duplicateHandle failed in createProcess\n");
-                }
-#endif
-            }
-            if (stdoutHandle) {
+		if (SetHandleInformation(stdinHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
+		    // good
+		} else {
+		    console_fprintf(stderr, "Win32OS [warning]: SetHandleInformation failed in createProcess\n");
+		}
+#else
+		if (DuplicateHandle(GetCurrentProcess(), stdinHandle, GetCurrentProcess(),
+				      &childHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
+		    stdinHandle = childHandle;
+		    mustClose_stdinHandle = 1;
+		} else {
+		    console_fprintf(stderr, "Win32OS [warning]: duplicateHandle failed in createProcess\n");
+		}
+#endif
+	    }
+	    if (stdoutHandle) {
 #if 0
-                if (SetHandleInformation(stdoutHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
-                    // good
-                } else {
-                    console_fprintf(stderr, "Win32OS [warning]: SetHandleInformation failed in createProcess\n");
-                }
-#else
-                if (DuplicateHandle(GetCurrentProcess(), stdoutHandle, GetCurrentProcess(),
-                                      &childHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
-                    stdoutHandle = childHandle;
-                    mustClose_stdoutHandle = 1;
-                } else {
-                    console_fprintf(stderr, "Win32OS [warning]: duplicateHandle failed in createProcess\n");
-                }
-#endif
-            }
-            if (stderrHandle) {
-                if (sameHandle) {
-                    stderrHandle = stdoutHandle;
-                } else {
+		if (SetHandleInformation(stdoutHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
+		    // good
+		} else {
+		    console_fprintf(stderr, "Win32OS [warning]: SetHandleInformation failed in createProcess\n");
+		}
+#else
+		if (DuplicateHandle(GetCurrentProcess(), stdoutHandle, GetCurrentProcess(),
+				      &childHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
+		    stdoutHandle = childHandle;
+		    mustClose_stdoutHandle = 1;
+		} else {
+		    console_fprintf(stderr, "Win32OS [warning]: duplicateHandle failed in createProcess\n");
+		}
+#endif
+	    }
+	    if (stderrHandle) {
+		if (sameHandle) {
+		    stderrHandle = stdoutHandle;
+		} else {
 #if 0
-                    if (SetHandleInformation(stderrHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
-                        // good
-                    } else {
-                        console_fprintf(stderr, "Win32OS [warning]: SetHandleInformation failed in createProcess\n");
-                    }
-#else
-                    if (DuplicateHandle(GetCurrentProcess(), stderrHandle, GetCurrentProcess(),
-                                          &childHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
-                        stderrHandle = childHandle;
-                        mustClose_stderrHandle = 1;
-                    } else {
-                        console_fprintf(stderr, "Win32OS [warning]: duplicateHandle failed in createProcess\n");
-                    }
-#endif
-                }
-            }
-        }
-        lpsiStartInfo.hStdInput  = stdinHandle;
-        lpsiStartInfo.hStdOutput = stdoutHandle;
-        lpsiStartInfo.hStdError  = stderrHandle;
-
-        if (doFork == true) {
+		    if (SetHandleInformation(stderrHandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
+			// good
+		    } else {
+			console_fprintf(stderr, "Win32OS [warning]: SetHandleInformation failed in createProcess\n");
+		    }
+#else
+		    if (DuplicateHandle(GetCurrentProcess(), stderrHandle, GetCurrentProcess(),
+					  &childHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
+			stderrHandle = childHandle;
+			mustClose_stderrHandle = 1;
+		    } else {
+			console_fprintf(stderr, "Win32OS [warning]: duplicateHandle failed in createProcess\n");
+		    }
+#endif
+		}
+	    }
+	}
+	lpsiStartInfo.hStdInput  = stdinHandle;
+	lpsiStartInfo.hStdOutput = stdoutHandle;
+	lpsiStartInfo.hStdError  = stderrHandle;
+
+	if (doFork == true) {
 #ifdef PROCESSDEBUGWIN32
-            console_fprintf(stderr, "create process cmdPath:<%s> cmdLine:<%s> in <%s>\n", cmdPath, cmdLine, dir);
-#endif
-            if (CreateProcessW( cmdPathWP,
-                                cmdLineWP,
-                                &securityAttributes, NULL /* &securityAttributes */,
-                                securityAttributes.bInheritHandle,      /* inherit handles */
-                                fdwCreate | CREATE_SUSPENDED,           /* resume after setting affinity */
-                                NULL,                                   /* env */
-                                dirNameWP,
-                                &lpsiStartInfo,
-                                &lppiProcInfo ))
-            {
-                DWORD_PTR processAffinityMask, systemAffinityMask;
-
-                /*
-                 * Process was created suspended, now set the affinity mask
-                 * to any processor, and resume the processes main thread.
-                 * (librun/process.s limited the affinity to a single processor).
-                 */
-                GetProcessAffinityMask(lppiProcInfo.hProcess, &processAffinityMask, &systemAffinityMask);
-                SetProcessAffinityMask(lppiProcInfo.hProcess, systemAffinityMask);
-                if ((fdwCreate & CREATE_SUSPENDED) == 0) {
-                    ResumeThread(lppiProcInfo.hThread);
-                }
-                CloseHandle(lppiProcInfo.hThread);
+	    if (flag_PROCESSDEBUGWIN32) {
+		console_fprintf(stderr, "create process cmdPath:<%s> cmdLine:<%s> in <%s>\n", cmdPath, cmdLine, dir);
+	    }
+#endif
+	    memset(&lppiProcInfo, 0, sizeof (lppiProcInfo));
+
+	    if (CreateProcessW( cmdPathWP,
+				cmdLineWP,
+				&securityAttributes, NULL /* &securityAttributes */,
+				securityAttributes.bInheritHandle,      /* inherit handles */
+				fdwCreate | CREATE_SUSPENDED,           /* resume after setting affinity */
+				NULL,                                   /* env */
+				dirNameWP,
+				&lpsiStartInfo,
+				&lppiProcInfo ))
+	    {
+		DWORD_PTR processAffinityMask, systemAffinityMask;
+
+		/*
+		 * Process was created suspended, now set the affinity mask
+		 * to any processor, and resume the processes main thread.
+		 * (librun/process.s limited the affinity to a single processor).
+		 */
+		GetProcessAffinityMask(lppiProcInfo.hProcess, &processAffinityMask, &systemAffinityMask);
+		SetProcessAffinityMask(lppiProcInfo.hProcess, systemAffinityMask);
+		if ((fdwCreate & CREATE_SUSPENDED) == 0) {
+		    ResumeThread(lppiProcInfo.hThread);
+		}
+		CloseHandle(lppiProcInfo.hThread);
 
 #if 0
-                // only works with real console handles
-                {
-                    // change the child's stdIn (console) mode
-                    DWORD mode = 0;
-
-                    if (! GetConsoleMode(stdinHandle, &mode)) {
-                        console_fprintf(stderr, "Win32OS [warning]: GetConsoleMode failed in createProcess\n");
-                    }
-                    if (! SetConsoleMode(stdinHandle, mode & (~ENABLE_ECHO_INPUT))){
-                        console_fprintf(stderr, "Win32OS [warning]: SetConsoleMode failed in createProcess\n");
-                    }
-                }
-#endif
-                if (mustClose_stdinHandle) {
-                    CloseHandle(stdinHandle);
-                }
-                if (mustClose_stdoutHandle) {
-                    CloseHandle(stdoutHandle);
-                }
-                if (mustClose_stderrHandle) {
-                    CloseHandle(stderrHandle);
-                }
+		// only works with real console handles
+		{
+		    // change the child's stdIn (console) mode
+		    DWORD mode = 0;
+
+		    if (! GetConsoleMode(stdinHandle, &mode)) {
+			console_fprintf(stderr, "Win32OS [warning]: GetConsoleMode failed in createProcess\n");
+		    }
+		    if (! SetConsoleMode(stdinHandle, mode & (~ENABLE_ECHO_INPUT))){
+			console_fprintf(stderr, "Win32OS [warning]: SetConsoleMode failed in createProcess\n");
+		    }
+		}
+#endif
+		if (mustClose_stdinHandle) {
+		    CloseHandle(stdinHandle);
+		}
+		if (mustClose_stdoutHandle) {
+		    CloseHandle(stdoutHandle);
+		}
+		if (mustClose_stderrHandle) {
+		    CloseHandle(stderrHandle);
+		}
 #ifdef PROCESSDEBUGWIN32
-                console_fprintf(stderr, "created process hProcess=%x\n", lppiProcInfo.hProcess);
-#endif
-
-                __externalAddressVal(handle) = lppiProcInfo.hProcess;
-                ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(handle))->pid = __mkSmallInteger(lppiProcInfo.dwProcessId);
-                RETURN (handle);
-            }
+		if (flag_PROCESSDEBUGWIN32) {
+		    console_fprintf(stderr, "created process hProcess=%x pid=%d\n", lppiProcInfo.hProcess, lppiProcInfo.dwProcessId);
+		}
+#endif
+
+		__externalAddressVal(handle) = lppiProcInfo.hProcess;
+		((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(handle))->pid = __mkSmallInteger(lppiProcInfo.dwProcessId);
+		RETURN (handle);
+	    }
 #ifdef PROCESSDEBUGWIN32
-            console_fprintf(stderr, "created process error %d\n", GetLastError());
-#endif
-            RETURN (nil);
-        } else {
-            ; /* should never be called that way */
-        }
+	    if (flag_PROCESSDEBUGWIN32) {
+		console_fprintf(stderr, "created process error %d\n", GetLastError());
+	    }
+#endif
+	    RETURN (nil);
+	} else {
+	    ; /* should never be called that way */
+	}
     }
 %}.
     "
@@ -4739,8 +4772,10 @@
 	goto badArgument;
     }
 #ifdef PROCESSDEBUGWIN32
-    console_fprintf(stderr, "name:<%s> access:%x share:%x create:%x attr:%x\n",
-		name, access, share, create, attr);
+    if (flag_PROCESSDEBUGWIN32) {
+	console_fprintf(stderr, "name:<%s> access:%x share:%x create:%x attr:%x\n",
+			name, access, share, create, attr);
+    }
 #endif
     if (__isStringLike(pathName)) {
 	h = CreateFileA(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
@@ -7449,8 +7484,10 @@
      * make fileDescriptors from handles
      */
 # ifdef PROCESSDEBUGWIN32
-    console_printf("piperead %x\n",pipeRead);
-    console_printf("pipewrite %x\n",pipeWrite);
+    if (flag_PROCESSDEBUGWIN32) {
+	console_printf("piperead %x\n",pipeRead);
+	console_printf("pipewrite %x\n",pipeWrite);
+    }
 # endif
     fd1 = __mkSmallInteger(_open_osfhandle(pipeRead, O_BINARY));
     fd2 = __mkSmallInteger(_open_osfhandle(pipeWrite, O_BINARY));
@@ -7476,7 +7513,9 @@
 
 	if (__pid != 0) {
 #ifdef PROCESSDEBUGWIN32
-	    console_printf("Close ProcessHandle %x\n", __pid);
+	    if (flag_PROCESSDEBUGWIN32) {
+		console_printf("Close ProcessHandle %x\n", __pid);
+	    }
 #endif
 	    CloseHandle(__pid);
 	    _SETHANDLEVal(pid, 0);
@@ -7786,7 +7825,7 @@
     "/ <apicall: dword "GetLastError" () module: "kernel32.dll" >
 
     "
-        self primGetLastError
+	self primGetLastError
     "
 !
 
@@ -7913,25 +7952,25 @@
 %{
     if (__isString(lpName)
      && ((bInitialOwner == true) || (bInitialOwner == false))) {
-        void *c_descr = NULL;
-        char *c_name;
-        HANDLE c_handle;
-
-        c_name = __stringVal(lpName);
-
-        if (lpSecurityDescriptor != nil) {
-            if (__isExternalAddressLike(lpSecurityDescriptor)
-             || __isExternalBytesLike(lpSecurityDescriptor) ) {
-                c_descr = __externalAddressVal(lpSecurityDescriptor);
-            } else
-                goto badArg;
-        }
-        c_handle = CreateMutexA(c_descr, bInitialOwner == true, c_name);
-        if (c_handle == NULL) {
-            RETURN(nil);
-        }
-        __externalAddressVal(handle) = c_handle;
-        RETURN(handle);
+	void *c_descr = NULL;
+	char *c_name;
+	HANDLE c_handle;
+
+	c_name = __stringVal(lpName);
+
+	if (lpSecurityDescriptor != nil) {
+	    if (__isExternalAddressLike(lpSecurityDescriptor)
+	     || __isExternalBytesLike(lpSecurityDescriptor) ) {
+		c_descr = __externalAddressVal(lpSecurityDescriptor);
+	    } else
+		goto badArg;
+	}
+	c_handle = CreateMutexA(c_descr, bInitialOwner == true, c_name);
+	if (c_handle == NULL) {
+	    RETURN(nil);
+	}
+	__externalAddressVal(handle) = c_handle;
+	RETURN(handle);
     }
     badArg: ;
 %}.
@@ -7952,25 +7991,25 @@
 %{
     if (__isString(lpName)
      && ((bInitialOwner == true) || (bInitialOwner == false))) {
-        DWORD c_dwDesiredAccess = 0;
-        char *c_name;
-        BOOL c_initialOwner = (bInitialOwner == true);
-        HANDLE c_handle;
-
-        c_name = __stringVal(lpName);
-
-        if (dwDesiredAccess != nil) {
-            if (! __isSmallInteger(dwDesiredAccess)) {
-                goto badArg;
-            }
-            c_dwDesiredAccess = __intVal(dwDesiredAccess);
-        }
-        c_handle = OpenMutexA(c_dwDesiredAccess, c_initialOwner, c_name);
-        if (c_handle == NULL) {
-            RETURN(nil);
-        }
-        __externalAddressVal(handle) = c_handle;
-        RETURN(handle);
+	DWORD c_dwDesiredAccess = 0;
+	char *c_name;
+	BOOL c_initialOwner = (bInitialOwner == true);
+	HANDLE c_handle;
+
+	c_name = __stringVal(lpName);
+
+	if (dwDesiredAccess != nil) {
+	    if (! __isSmallInteger(dwDesiredAccess)) {
+		goto badArg;
+	    }
+	    c_dwDesiredAccess = __intVal(dwDesiredAccess);
+	}
+	c_handle = OpenMutexA(c_dwDesiredAccess, c_initialOwner, c_name);
+	if (c_handle == NULL) {
+	    RETURN(nil);
+	}
+	__externalAddressVal(handle) = c_handle;
+	RETURN(handle);
     }
     badArg: ;
 %}.