initial checkin
authorStefan Vogel <sv@exept.de>
Thu, 22 Dec 2016 13:56:30 +0100
changeset 21160 cc6d597ab14b
parent 21159 6311fdcf8f6c
child 21161 0bacd2c2b231
initial checkin
OsProcess.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OsProcess.st	Thu Dec 22 13:56:30 2016 +0100
@@ -0,0 +1,236 @@
+"
+ COPYRIGHT (c) 1998 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+"{ Package: 'stx:libbasic' }"
+
+"{ NameSpace: Smalltalk }"
+
+Object subclass:#OsProcess
+	instanceVariableNames:'command environment directory inStream outStream errorStream pid
+		exitStatus finishSema'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'OS-Windows'
+!
+
+!OsProcess class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1998 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+! !
+
+!OsProcess methodsFor:'accessing'!
+
+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"
+!
+
+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"
+!
+
+pid
+    "return the value of the instance variable 'pid' (automatically generated)"
+
+    ^ pid
+
+    "Created: / 10.11.1998 / 21:21:53 / cg"
+!
+
+pid:something
+    "set the value of the instance variable 'pid' (automatically generated)"
+
+    pid := something.
+
+    "Created: / 10.11.1998 / 21:21:53 / cg"
+! !
+
+!OsProcess methodsFor:'starting'!
+
+startProcess
+    finishSema := Semaphore new.
+
+    pid := Processor 
+                monitor:[
+                    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 class methodsFor:'documentation'!
+
+version
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
+! !
+