--- a/Win32OperatingSystem.st Mon Mar 02 18:14:50 2009 +0100
+++ b/Win32OperatingSystem.st Mon Mar 02 18:38:18 2009 +0100
@@ -3384,6 +3384,89 @@
"Modified: / 15.5.1999 / 18:07:51 / cg"
!
+exec:commandString withArguments:argString
+ 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
+ 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
+ The command gets stdIn, stdOut and stdErr assigned from the arguments;
+ each may be nil.
+ Return the processId if successful, nil otherwise.
+ Use #monitorPid:action: for synchronization and exec status return,
+ or #killProcess: to stop it."
+
+ |nullStream in out err rslt auxFd|
+
+ (in := anExternalInStream) isNil ifTrue:[
+ nullStream := Filename nullDevice readWriteStream.
+ in := nullStream.
+ ].
+ (out := anExternalOutStream) isNil ifTrue:[
+ nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
+ out := nullStream.
+ ].
+ (err := anExternalErrStream) isNil ifTrue:[
+ err := out
+ ].
+ anAuxiliaryStream notNil ifTrue:[
+ auxFd := anAuxiliaryStream fileDescriptor
+ ].
+
+ rslt := self
+ exec:commandString
+ withArguments:argString
+ 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.
+ ].
+ ^ 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-03-1997 / 10:04:35 / dq"
+ "Modified: / 15-07-1997 / 16:03:51 / stefan"
+ "Created: / 12-11-1998 / 14:39:20 / cg"
+ "Modified: / 11-02-2007 / 20:13:28 / cg"
+!
+
getStatusOfProcess:aProcessId
"wait for a process to terminate and fetch its exit status.
This is required to avoid zombie processes."
@@ -3711,43 +3794,17 @@
Use #monitorPid:action: for synchronization and exec status return,
or #killProcess: to stop it."
- |nullStream in out err shellAndArgs rslt auxFd|
+ |shellAndArgs|
aCommandString isNil ifTrue:[^ nil].
- (in := anExternalInStream) isNil ifTrue:[
- nullStream := Filename nullDevice readWriteStream.
- in := nullStream.
- ].
- (out := anExternalOutStream) isNil ifTrue:[
- nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
- out := nullStream.
- ].
- (err := anExternalErrStream) isNil ifTrue:[
- err := out
- ].
- anAuxiliaryStream notNil ifTrue:[
- auxFd := anAuxiliaryStream fileDescriptor
- ].
-
shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
- 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.
- ].
- ^ rslt
+ ^ self
+ exec:(shellAndArgs at:1) withArguments:(shellAndArgs at:2)
+ inputFrom:anExternalInStream outputTo:anExternalOutStream
+ errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
+ environment:anEvironmentDictionary inDirectory:dir
"blocking at current prio (i.e. only higher prio threads execute):
@@ -3768,7 +3825,7 @@
The following will no longer work. monitorPid has disappeared
pid notNil ifTrue:[
- Processor monitorPid:pid action:[:OSstatus | sema signal ].
+ Processor monitorPid:pid action:[:OSstatus | sema signal ].
].
in close.
out close.
@@ -15914,7 +15971,7 @@
!Win32OperatingSystem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.361 2009-02-20 14:14:40 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.362 2009-03-02 17:38:18 mb Exp $'
! !
Win32OperatingSystem initialize!