OSProcess.st
changeset 21172 36a0e5430705
parent 20379 135c4fc19014
child 21181 a8a9220ed86f
--- a/OSProcess.st	Thu Dec 22 14:53:36 2016 +0100
+++ b/OSProcess.st	Thu Dec 22 14:56:04 2016 +0100
@@ -3,7 +3,8 @@
 "{ NameSpace: Smalltalk }"
 
 Object subclass:#OSProcess
-	instanceVariableNames:'pid parentPid commandLine'
+	instanceVariableNames:'pid parentPid command environment directory inStream outStream
+		errorStream exitStatus finishSema'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Support'
@@ -32,18 +33,145 @@
 "
 ! !
 
+!OSProcess class methodsFor:'initialize'!
+
+initialize
+    "Backward compatibility"
+    Win32Process := self.
+! !
+
 !OSProcess methodsFor:'accessing'!
 
 accessor
     ^ self
 !
 
-commandLine
-    ^ commandLine
+command
+    "return the value of the instance variable 'command' (automatically generated)"
+
+    ^ command
+
+    "Created: / 10.11.1998 / 21:27:07 / cg"
+!
+
+command:something
+    "set the value of the instance variable 'command' (automatically generated)"
+
+    command := something.
+
+    "Created: / 10.11.1998 / 21:27:07 / cg"
+!
+
+directory
+    "return the value of the instance variable 'directory' (automatically generated)"
+
+    ^ directory
+
+    "Created: / 10.11.1998 / 21:21:52 / cg"
+!
+
+directory:something
+    "set the value of the instance variable 'directory' (automatically generated)"
+
+    directory := something.
+
+    "Created: / 10.11.1998 / 21:21:52 / cg"
+!
+
+environment
+    "return the value of the instance variable 'environment' (automatically generated)"
+
+    ^ environment
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
+!
+
+environment:something
+    "set the value of the instance variable 'environment' (automatically generated)"
+
+    environment := something.
+
+    "Created: / 10.11.1998 / 21:27:07 / cg"
+!
+
+errorStream
+    "return the value of the instance variable 'errorStream' (automatically generated)"
+
+    ^ errorStream
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
 !
 
-commandLine:something
-    commandLine := something.
+errorStream:something
+    "set the value of the instance variable 'errorStream' (automatically generated)"
+
+    errorStream := something.
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
+!
+
+exitStatus
+    "return the value of the instance variable 'exitStatus' (automatically generated)"
+
+    ^ exitStatus
+
+    "Created: / 10.11.1998 / 21:24:55 / cg"
+!
+
+exitStatus:something
+    "set the value of the instance variable 'exitStatus' (automatically generated)"
+
+    exitStatus := something.
+
+    "Created: / 10.11.1998 / 21:24:55 / cg"
+!
+
+finishSema
+    "return the value of the instance variable 'finishSema' (automatically generated)"
+
+    ^ finishSema
+
+    "Created: / 10.11.1998 / 21:21:53 / cg"
+!
+
+finishSema:something
+    "set the value of the instance variable 'finishSema' (automatically generated)"
+
+    finishSema := something.
+
+    "Created: / 10.11.1998 / 21:21:53 / cg"
+!
+
+inStream
+    "return the value of the instance variable 'inStream' (automatically generated)"
+
+    ^ inStream
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
+!
+
+inStream:something
+    "set the value of the instance variable 'inStream' (automatically generated)"
+
+    inStream := something.
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
+!
+
+outStream
+    "return the value of the instance variable 'outStream' (automatically generated)"
+
+    ^ outStream
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
+!
+
+outStream:something
+    "set the value of the instance variable 'outStream' (automatically generated)"
+
+    outStream := something.
+
+    "Created: / 10.11.1998 / 21:26:34 / cg"
 !
 
 parentPid
@@ -76,7 +204,7 @@
         nextPut:$(.
     pid printOn:aStream.
     aStream space.
-    commandLine printOn:aStream.
+    command printOn:aStream.
     aStream nextPut:$)
 ! !
 
@@ -102,6 +230,47 @@
     ^ self isAlive not
 ! !
 
+!OSProcess methodsFor:'starting'!
+
+startProcess
+    finishSema := Semaphore new.
+
+    Processor 
+        monitor:[
+            pid := OperatingSystem
+                startProcess:command
+                inputFrom:inStream
+                outputTo:outStream
+                errorTo:errorStream
+                auxFrom:nil
+                environment:nil
+                inDirectory:directory
+                showWindow:false.
+        ] 
+        action:[:status |
+            status stillAlive ifFalse:[
+                exitStatus := status.
+                "/ paranoia?
+                pid notNil ifTrue:[
+                    OperatingSystem terminateProcessGroup:pid.
+                    OperatingSystem terminateProcess:pid.
+                    OperatingSystem closePid:pid.
+                ].
+                finishSema signal
+            ].
+        ].
+
+    pid isNil ifTrue:[
+        exitStatus := OperatingSystem osProcessStatusClass processCreationFailure.
+        ^ false
+    ].
+
+    ^ true.
+
+    "Created: / 10.11.1998 / 21:23:50 / cg"
+    "Modified: / 10.11.1998 / 21:33:16 / cg"
+! !
+
 !OSProcess methodsFor:'terminating'!
 
 kill
@@ -152,3 +321,5 @@
     ^ '$Header$'
 ! !
 
+
+OSProcess initialize!