Win32OperatingSystem.st
changeset 7638 a211d1f10797
parent 7535 9bcb9a436394
child 7645 fd98d4cfa617
--- a/Win32OperatingSystem.st	Wed Oct 08 14:43:59 2003 +0200
+++ b/Win32OperatingSystem.st	Wed Oct 08 14:45:01 2003 +0200
@@ -2686,56 +2686,59 @@
     "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 process id of the child process is returned; nil if the fork failed.
+        fork a child to do the above.
+        The process id 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
-	on VMS, these must be channels as returned by createMailBox.
+        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
+        on VMS, these must be channels as returned by createMailBox.
 
      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."
-
-    |dirPath cmdPath cmdLine|
+        The processgroup will be equal to id.
+        newPgrp is not used on WIN32 and VMS systems."
+
+    |dirPath cmdPath cmdLine rslt|
 
     aDirectory notNil ifTrue:[
-	dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory.
-	(dirPath endsWith:':') ifTrue:[
-	    dirPath := dirPath , '\'.
-	].
+        dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory.
+        (dirPath endsWith:':') ifTrue:[
+            dirPath := dirPath , '\'.
+        ].
     ].
 
     self isMSWINDOWSNTlike ifTrue:[
-	cmdPath := aCommandPath.
-	cmdLine := argString
+        cmdPath := aCommandPath.
+        cmdLine := argString
     ] ifFalse:[
-	cmdPath := 'stxspawn.exe'.
-	cmdLine := 'stxspawn.exe ' , aCommandPath , ' ' , argString
+        cmdPath := 'stxspawn.exe'.
+        cmdLine := 'stxspawn.exe ' , aCommandPath , ' ' , argString
     ].
 
-    ^ self 
-	primExec:cmdPath 
-	commandLine:cmdLine 
-	fileDescriptors:fdArray 
-	fork:doFork 
-	newPgrp:newPgrp 
-	inPath:dirPath
-	createFlags:nil
+    rslt := self 
+        primExec:cmdPath 
+        commandLine:cmdLine 
+        fileDescriptors:fdArray 
+        fork:doFork 
+        newPgrp:newPgrp 
+        inPath:dirPath
+        createFlags:nil.
+
+'ctreated ' print. aCommandPath print. ' -> ' print. rslt printCR.
+    ^ rslt
 
     "Modified: / 31.1.1998 / 10:54:24 / md"
     "Modified: / 15.5.1999 / 18:07:51 / cg"
@@ -3023,7 +3026,10 @@
     ^ self primitiveFailed
 !
 
-startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream auxFrom:anExternalAuxStream inDirectory:dirOrNil
+startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream 
+    errorTo:anExternalErrStream auxFrom:anAuxiliaryStream 
+    environment:anEvironmentDictionary inDirectory:dir
+
     "start executing the OS command as specified by the argument, aCommandString
      as a separate process; do not wait for the command to finish.
      The commandString is passed to a shell for execution - see the description of
@@ -3034,67 +3040,77 @@
      Use #monitorPid:action: for synchronization and exec status return,
      or #killProcess: to stop it."
 
-    |ret in out err shellAndArgs errStream outStream inStream|
+    |nullStream in out err shellAndArgs rslt auxFd|
 
     aCommandString isNil ifTrue:[^ nil].
 
-    anExternalInStream notNil ifTrue:[
-	in := anExternalInStream fileDescriptor.
-    ] ifFalse:[
-	self isMSWINDOWSNTlike ifTrue:[
-	    inStream := 'nul' asFilename readStream.
-	    inStream notNil ifTrue:[
-		in := inStream fileDescriptor.
-	    ]
-	]
+    (in := anExternalInStream) isNil ifTrue:[
+        nullStream := Filename nullDevice readWriteStream.
+        in := nullStream. 
     ].
-    anExternalOutStream notNil ifTrue:[
-	out := anExternalOutStream fileDescriptor.
-    ] ifFalse:[
-	self isMSWINDOWSNTlike ifTrue:[
-	    outStream := 'nul' asFilename writeStream.
-	    outStream notNil ifTrue:[
-		out := outStream fileDescriptor.
-	    ]
-	]
+    (out := anExternalOutStream) isNil ifTrue:[
+        nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
+        out := nullStream.
     ].
-    anExternalErrStream notNil ifTrue:[
-	err := anExternalErrStream fileDescriptor.
-    ] ifFalse:[
-	self isMSWINDOWSNTlike ifTrue:[
-	    errStream := 'nul' asFilename writeStream.
-	    errStream notNil ifTrue:[
-		err := errStream fileDescriptor.
-	    ]
-	]
+    (err := anExternalErrStream) isNil ifTrue:[
+        err := out
     ].
-    anExternalAuxStream notNil ifTrue:[
-	self error:'Aux stream is not supported in Windows' mayProceed:true.
+    anAuxiliaryStream notNil ifTrue:[
+        auxFd := anAuxiliaryStream fileDescriptor
     ].
 
     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
-    ret := self
-	exec:(shellAndArgs at:1)
-	withArguments:(shellAndArgs at:2)
-	environment:nil
-	fileDescriptors:(Array with:in with:out with:err)
-	fork:true
-	newPgrp:false
-	inDirectory:dirOrNil.
-
-    inStream notNil ifTrue:[
-	inStream close
+
+    rslt := self
+        exec:(shellAndArgs at:1)
+        withArguments:(shellAndArgs at:2)
+        environment:anEvironmentDictionary
+        fileDescriptors:(Array with:in fileDescriptor
+                               with:out fileDescriptor
+                               with:err fileDescriptor
+                               with:auxFd)
+        fork:true
+        newPgrp:true "/ false
+        inDirectory:dir.
+
+    nullStream notNil ifTrue:[
+        nullStream close.
     ].
-    outStream notNil ifTrue:[
-	outStream close
-    ].
-    errStream notNil ifTrue:[
-	errStream close
-    ].
-    ^ ret
-
-    "Created: / 10.11.1998 / 20:48:35 / cg"
-    "Modified: / 19.5.1999 / 10:43:01 / cg"
+self halt.
+    ^ rslt
+
+    "blocking at current prio (i.e. only higher prio threads execute):
+
+     OperatingSystem executeCommand:'ls -l > out'.
+    "
+
+    "non-blocking (lower prio threads continue):
+
+     |in out err pid sema|
+
+     in := 'out' asFilename readStream.
+     out := 'out2' asFilename writeStream.
+     err := 'err' asFilename writeStream.
+
+     sema := Semaphore new.
+     pid := OperatingSystem startProcess:'sleep 10; grep drw' inputFrom:in outputTo:out errorTo:err.
+
+     The following will no longer work. monitorPid has disappeared 
+
+     pid notNil ifTrue:[
+         Processor monitorPid:pid action:[:OSstatus | sema signal ].
+     ].
+     in close.
+     out close.
+     err close.
+     sema wait.
+     Transcript showCR:'finished'
+    "
+
+    "Modified: / 21.3.1997 / 10:04:35 / dq"
+    "Modified: / 15.7.1997 / 16:03:51 / stefan"
+    "Modified: / 5.6.1998 / 19:03:51 / cg"
+    "Created: / 12.11.1998 / 14:39:20 / cg"
 ! !
 
 !Win32OperatingSystem class methodsFor:'file access'!
@@ -6325,67 +6341,6 @@
 
 !
 
-timeInfoFromSeconds:osSeconds localTime:isLocalTime
-    "return a timeInfo structure containing values for the given
-     OS-second value.
-     An internal helper"
-
-    |low hi year month day hours minutes seconds utcOffset 
-     dst yDay wDay info|
-
-%{
-    struct tm *tmPtr;
-    struct tm *gmTmPtr;
-    INT t;
-    TIME_T tt;
-
-    t = __longIntVal(osSeconds);
-    tt = (TIME_T)t;
-
-    tmPtr = localtime(&tt);
-    hours = __MKSMALLINT(tmPtr->tm_hour);
-    minutes = __MKSMALLINT(tmPtr->tm_min);
-    seconds = __MKSMALLINT(tmPtr->tm_sec);
-
-    year = __MKSMALLINT(tmPtr->tm_year + 1900);
-    month = __MKSMALLINT(tmPtr->tm_mon + 1);
-    day = __MKSMALLINT(tmPtr->tm_mday);
-
-    yDay = __MKSMALLINT(tmPtr->tm_yday+1);
-    wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday);
-
-    if (tmPtr->tm_isdst == 0) {
-	dst = false;
-	utcOffset = __MKINT(TIMEZONE(tmPtr));
-    } else {
-	dst = true;
-#ifdef HAS_ALTZONE
-	utcOffset = __MKINT(altzone);
-#else
-	utcOffset = __MKINT(TIMEZONE(tmPtr) + 3600);
-#endif
-    }
-%}.
-    info := self timeInfoClass new.
-
-    info
-	year:year
-	month:month
-	day:day
-	hours:hours
-	minutes:minutes
-	seconds:seconds
-	utcOffset:utcOffset
-	dst:dst
-	dayInYear:yDay
-	dayInWeek:wDay.
-    ^ info
-
-    "
-     OperatingSystem timeInfoFromSeconds:0 localTime:false
-    "
-!
-
 computeTimePartsOf:osTime for:aBlock
     "compute hours, minutes, seconds and milliseconds from the osTime 
      and evaluate the argument, a 4-arg block with these.
@@ -6706,6 +6661,67 @@
     "
      OperatingSystem sleep:2
     "
+!
+
+timeInfoFromSeconds:osSeconds localTime:isLocalTime
+    "return a timeInfo structure containing values for the given
+     OS-second value.
+     An internal helper"
+
+    |low hi year month day hours minutes seconds utcOffset 
+     dst yDay wDay info|
+
+%{
+    struct tm *tmPtr;
+    struct tm *gmTmPtr;
+    INT t;
+    TIME_T tt;
+
+    t = __longIntVal(osSeconds);
+    tt = (TIME_T)t;
+
+    tmPtr = localtime(&tt);
+    hours = __MKSMALLINT(tmPtr->tm_hour);
+    minutes = __MKSMALLINT(tmPtr->tm_min);
+    seconds = __MKSMALLINT(tmPtr->tm_sec);
+
+    year = __MKSMALLINT(tmPtr->tm_year + 1900);
+    month = __MKSMALLINT(tmPtr->tm_mon + 1);
+    day = __MKSMALLINT(tmPtr->tm_mday);
+
+    yDay = __MKSMALLINT(tmPtr->tm_yday+1);
+    wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday);
+
+    if (tmPtr->tm_isdst == 0) {
+	dst = false;
+	utcOffset = __MKINT(TIMEZONE(tmPtr));
+    } else {
+	dst = true;
+#ifdef HAS_ALTZONE
+	utcOffset = __MKINT(altzone);
+#else
+	utcOffset = __MKINT(TIMEZONE(tmPtr) + 3600);
+#endif
+    }
+%}.
+    info := self timeInfoClass new.
+
+    info
+	year:year
+	month:month
+	day:day
+	hours:hours
+	minutes:minutes
+	seconds:seconds
+	utcOffset:utcOffset
+	dst:dst
+	dayInYear:yDay
+	dayInWeek:wDay.
+    ^ info
+
+    "
+     OperatingSystem timeInfoFromSeconds:0 localTime:false
+    "
 ! !
 
 !Win32OperatingSystem class methodsFor:'users & groups'!
@@ -8824,7 +8840,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.132 2003-07-25 20:19:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.133 2003-10-08 12:45:01 mb Exp $'
 ! !
 
 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
@@ -8851,7 +8867,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.132 2003-07-25 20:19:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.133 2003-10-08 12:45:01 mb Exp $'
 ! !
 
 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
@@ -9238,7 +9254,7 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.132 2003-07-25 20:19:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.133 2003-10-08 12:45:01 mb Exp $'
 ! !
 
 Win32OperatingSystem initialize!