diff -r d8eaf4da9e34 -r 8d74e1a4c65f AbstractOperatingSystem.st --- a/AbstractOperatingSystem.st Tue Jul 10 13:58:33 2018 +0200 +++ b/AbstractOperatingSystem.st Tue Jul 10 16:38:12 2018 +0200 @@ -911,8 +911,9 @@ !AbstractOperatingSystem class methodsFor:'executing OS commands-implementation'! exec:aCommandPath withArguments:argArray environment:env fileDescriptors:fds fork:doFork - newPgrp:newGrp inDirectory:aDirectory showWindow:showWindowBooleanOrNil - "execute an OS command" + newPgrp:newGrp inDirectory:aDirectory showWindow:showWindowBooleanOrNil + "execute an OS command, return a pid. + Notice: on Unix, this id is an integer; on Windows, it is a processhandle." ^ self subclassResponsibility @@ -950,6 +951,7 @@ The command gets stdIn, stdOut and stdErr assigned from the arguments; each may be nil. Return the processId if successful, nil otherwise. + Notice: on Unix, this id is an integer; on Windows, it is a processhandle. Use #monitorPid:action: for synchronization and exec status return, or #killProcess: to stop it." @@ -958,37 +960,37 @@ aCommandString isNil ifTrue:[^ nil]. (in := anExternalInStream) isNil ifTrue:[ - nullStream := Filename nullDevice readWriteStream. - in := nullStream. + nullStream := Filename nullDevice readWriteStream. + in := nullStream. ]. (out := anExternalOutStream) isNil ifTrue:[ - nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream]. - out := nullStream. + nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream]. + out := nullStream. ]. (err := anExternalErrStream) isNil ifTrue:[ - err := out + err := out ]. anAuxiliaryStream notNil ifTrue:[ - auxFd := anAuxiliaryStream fileHandle. + auxFd := anAuxiliaryStream fileHandle. ]. shellAndArgs := self commandAndArgsForOSCommand:aCommandString. pid := self - exec:(shellAndArgs at:1) - withArguments:(shellAndArgs at:2) - environment:anEvironmentDictionary - fileDescriptors:(Array with:in fileHandle - with:out fileHandle - with:err fileHandle - with:auxFd) - fork:true - newPgrp:newPgrp - inDirectory:dir - showWindow:(showWindowBooleanOrNil ? (shellAndArgs at:3)). + exec:(shellAndArgs at:1) + withArguments:(shellAndArgs at:2) + environment:anEvironmentDictionary + fileDescriptors:(Array with:in fileHandle + with:out fileHandle + with:err fileHandle + with:auxFd) + fork:true + newPgrp:newPgrp + inDirectory:dir + showWindow:(showWindowBooleanOrNil ? (shellAndArgs at:3)). nullStream notNil ifTrue:[ - nullStream close. + nullStream close. ]. ^ pid @@ -1013,7 +1015,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. @@ -1028,10 +1030,10 @@ sema := Semaphore new. Processor - monitor:[ - pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err' - ] - action:[:osStatus | sema signal ]. + monitor:[ + pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err' + ] + action:[:osStatus | sema signal ]. sema wait. Transcript showCR:'finished' @@ -1043,10 +1045,10 @@ sema := Semaphore new. Processor - monitor:[ - pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err' - ] - action:[:osStatus | sema signal ]. + monitor:[ + pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err' + ] + action:[:osStatus | sema signal ]. Delay waitForSeconds:2. OperatingSystem terminateProcess:pid. @@ -1077,7 +1079,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. @@ -1092,10 +1094,10 @@ sema := Semaphore new. Processor - monitor:[ - pid := OperatingSystem startProcess:'dir > out 2>err' - ] - action:[:osStatus | sema signal ]. + monitor:[ + pid := OperatingSystem startProcess:'dir > out 2>err' + ] + action:[:osStatus | sema signal ]. sema wait. Transcript showCR:'finished' @@ -1107,10 +1109,10 @@ sema := Semaphore new. Processor - monitor:[ - pid := OperatingSystem startProcess:'(echo 1 & stx --eval "Delay waitForSeconds:100" & dir) >out' withCRs - ] - action:[:osStatus | sema signal ]. + monitor:[ + pid := OperatingSystem startProcess:'(echo 1 & stx --eval "Delay waitForSeconds:100" & dir) >out' withCRs + ] + action:[:osStatus | sema signal ]. Delay waitForSeconds:5. OperatingSystem terminateProcessGroup:pid. @@ -1123,10 +1125,10 @@ sema := Semaphore new. Processor - monitor:[ - pid := OperatingSystem startProcess:{ 'C:\Users\cg\work\stx\projects\smalltalk\stx.com' . '--eval' . '"Delay waitForSeconds:100"' } - ] - action:[:osStatus | sema signal ]. + monitor:[ + pid := OperatingSystem startProcess:{ 'C:\Users\cg\work\stx\projects\smalltalk\stx.com' . '--eval' . '"Delay waitForSeconds:100"' } + ] + action:[:osStatus | sema signal ]. Delay waitForSeconds:5. OperatingSystem terminateProcess:pid.