OSProcess.st
branchjv
changeset 21387 e3865533e6a6
parent 21252 1b7c2d5523d5
parent 21332 18ca24f32565
equal deleted inserted replaced
21331:1c4f9355fba3 21387:e3865533e6a6
   327 
   327 
   328     "/ start a reader process, shuffling data from the given
   328     "/ start a reader process, shuffling data from the given
   329     "/ inStream to the pipe (which is connected to the commands input)
   329     "/ inStream to the pipe (which is connected to the commands input)
   330     shufflerProcess := [
   330     shufflerProcess := [
   331             [
   331             [
   332                 WriteError handle:[:ex |"ignored" ] do:[
   332                 lineWise ifTrue:[
   333                     lineWise ifTrue:[
   333                     "shuffle until end-of-input"
   334                         "shuffle until end-of-input"
   334                     [aStream atEnd] whileFalse:[
   335                         [aStream atEnd] whileFalse:[
   335                         |data|
   336                             |data|
   336 
   337 
   337                         data := aStream nextLine.
   338                             data := aStream nextLine.
   338                         data notNil ifTrue:[
   339                             data notNil ifTrue:[
   339                             shuffledStream nextPutLine:data.
   340                                 shuffledStream nextPutLine:data.
   340                             shuffledStream flush.
   341                                 shuffledStream flush.
       
   342                             ].
       
   343                         ].
   341                         ].
   344                     ] ifFalse:[
       
   345                         aStream copyToEndInto:shuffledStream.
       
   346                     ].
   342                     ].
       
   343                 ] ifFalse:[
       
   344                     aStream copyToEndInto:shuffledStream.
   347                 ].
   345                 ].
       
   346             ] on:WriteError do:[:ex|
       
   347                 "ignore"
   348             ] ensure:[
   348             ] ensure:[
   349                 shuffledStream close.
   349                 shuffledStream close.
   350             ]
   350             ]
   351         ] newProcess
   351         ] newProcess
   352             name:'OSProcess input shuffler';
   352             name:'OSProcess input shuffler';
   355 
   355 
   356     shufflerProcesses add:shufflerProcess.
   356     shufflerProcesses add:shufflerProcess.
   357     streamsToClose add:externalStream.
   357     streamsToClose add:externalStream.
   358 
   358 
   359     ^ externalStream
   359     ^ externalStream
       
   360 
       
   361     "Modified: / 31-01-2017 / 16:50:39 / stefan"
   360 !
   362 !
   361 
   363 
   362 setupShufflerForOutput:aStream
   364 setupShufflerForOutput:aStream
   363     "if aStream is an internal Stream, set up a pipe for the command output.
   365     "if aStream is an internal Stream, set up a pipe for the command output.
   364      Start a process that shuffles the data fron the pipe into the internal stream."
   366      Start a process that shuffles the data fron the pipe into the internal stream."
   375     aStream isBinary ifTrue:[
   377     aStream isBinary ifTrue:[
   376         shuffledStream binary.
   378         shuffledStream binary.
   377     ].
   379     ].
   378 
   380 
   379     shufflerProcess := [
   381     shufflerProcess := [
   380             WriteError handle:[:ex |"ignored" ] do:[
   382             [
   381                 [
   383                 "shuffle until the pipe closes"
   382                     "shuffle until the pipe closes"
   384                 lineWise ifTrue:[
   383                     lineWise ifTrue:[
   385                     [shuffledStream atEnd] whileFalse:[
   384                         [shuffledStream atEnd] whileFalse:[
   386                         |data|
   385                             |data|
   387 
   386 
   388                         data := shuffledStream nextLine.
   387                             data := shuffledStream nextLine.
   389                         data notNil ifTrue:[
   388                             data notNil ifTrue:[
   390                             aStream nextPutLine:data
   389                                 aStream nextPutLine:data
       
   390                             ].
       
   391                         ].
   391                         ].
   392                     ] ifFalse:[
       
   393                         shuffledStream copyToEndInto:aStream.
       
   394                     ].
   392                     ].
   395                 ] ensure:[
   393                 ] ifFalse:[
   396                     shuffledStream close.
   394                     shuffledStream copyToEndInto:aStream.
   397                 ].
   395                 ].
       
   396             ] on:WriteError do:[:ex |
       
   397                 "ignore" 
       
   398             ] ensure:[
       
   399                 shuffledStream close.
   398             ].
   400             ].
   399         ] newProcess
   401         ] newProcess
   400             priority:(Processor userSchedulingPriority "+ 1");
   402             priority:(Processor userSchedulingPriority "+ 1");
   401             name:'OSProcess output shuffler';
   403             name:'OSProcess output shuffler';
   402 "/                beSystemProcess;
   404 "/                beSystemProcess;
   404 
   406 
   405     shufflerProcesses add:shufflerProcess.
   407     shufflerProcesses add:shufflerProcess.
   406     streamsToClose add:externalStream.
   408     streamsToClose add:externalStream.
   407 
   409 
   408     ^ externalStream
   410     ^ externalStream
       
   411 
       
   412     "Modified: / 31-01-2017 / 16:57:25 / stefan"
   409 ! !
   413 ! !
   410 
   414 
   411 !OSProcess methodsFor:'queries'!
   415 !OSProcess methodsFor:'queries'!
   412 
   416 
   413 finishedWithSuccess
   417 finishedWithSuccess