PipeStream.st
changeset 2985 eff9e86dd2f9
parent 2976 dcb3a0f7f2f9
child 2989 c96b2a254daa
equal deleted inserted replaced
2984:c407716ed1bc 2985:eff9e86dd2f9
   268     "
   268     "
   269 
   269 
   270     "Modified: 24.4.1996 / 09:09:25 / stefan"
   270     "Modified: 24.4.1996 / 09:09:25 / stefan"
   271 !
   271 !
   272 
   272 
       
   273 readingFrom:commandString errorDisposition:handleError inDirectory:aDirectory
       
   274     "similar to #readingFrom, but changes the directory while
       
   275      executing the command. Use this if a command is to be
       
   276      executed in another directory, to avoid any OS dependencies
       
   277      in your code.
       
   278      handleError may be one of #discard #inline #stderr (default), which causes
       
   279      stderr to me discarded (/dev/null), merged into the PipeStream or written
       
   280      to smalltalks stderr."
       
   281 
       
   282     |cmd tmpComFile pipe|
       
   283 
       
   284     (OperatingSystem platformName == #vms) ifTrue:[
       
   285         tmpComFile := OperatingSystem createCOMFileForVMSCommand:commandString in:aDirectory.
       
   286         cmd := '@' , tmpComFile osName.
       
   287         pipe := self readingFrom:cmd.
       
   288         pipe notNil ifTrue:[
       
   289             pipe exitAction:[tmpComFile delete].
       
   290         ].
       
   291         ^ pipe
       
   292     ].
       
   293 
       
   294     "/ unix - prepend a 'cd' to the command
       
   295     cmd := 'cd ' , aDirectory asFilename pathName, '; ' , commandString.
       
   296     handleError == #discard ifTrue:[
       
   297         cmd := cmd, ' 2>/dev/null'.
       
   298     ] ifFalse:[handleError == #inline ifTrue:[
       
   299         cmd := cmd, ' 2>&1'.
       
   300     ]].
       
   301     ^ self readingFrom:cmd
       
   302 
       
   303     "Created: 24.9.1997 / 09:32:35 / stefan"
       
   304 !
       
   305 
   273 readingFrom:commandString inDirectory:aDirectory
   306 readingFrom:commandString inDirectory:aDirectory
   274     "similar to #readingFrom, but changes the directory while
   307     "similar to #readingFrom, but changes the directory while
   275      executing the command. Use this if a command is to be
   308      executing the command. Use this if a command is to be
   276      executed in another directory, to avoid any OS dependencies
   309      executed in another directory, to avoid any OS dependencies
   277      in your code."
   310      in your code."
   278 
   311 
   279     |cmd tmpComFile pipe|
   312      ^ self readingFrom:commandString errorDisposition:#stderr inDirectory:aDirectory
   280 
   313 
   281     (OperatingSystem platformName == #vms) ifTrue:[
   314     "Modified: 24.9.1997 / 09:33:48 / stefan"
   282 	tmpComFile := OperatingSystem createCOMFileForVMSCommand:commandString in:aDirectory.
       
   283 	cmd := '@' , tmpComFile osName.
       
   284 	pipe := self readingFrom:cmd.
       
   285 	pipe notNil ifTrue:[
       
   286 	    pipe exitAction:[tmpComFile delete].
       
   287 	].
       
   288 	^ pipe
       
   289     ].
       
   290 
       
   291     "/ unix - prepend a 'cd' to the command
       
   292     cmd := 'cd ' , aDirectory asFilename pathName, '; ' , commandString.
       
   293     ^ self readingFrom:cmd
       
   294 !
   315 !
   295 
   316 
   296 writingTo:commandString
   317 writingTo:commandString
   297     "create and return a new pipeStream which can write to the unix command
   318     "create and return a new pipeStream which can write to the unix command
   298      given by command."
   319      given by command."
   328 ! !
   349 ! !
   329 
   350 
   330 !PipeStream class methodsFor:'Signal constants'!
   351 !PipeStream class methodsFor:'Signal constants'!
   331 
   352 
   332 brokenPipeSignal
   353 brokenPipeSignal
   333     "return the signal used to handle SIGPIPE unix-signals"
   354     "return the signal used to handle SIGPIPE unix-signals.
       
   355      Since SIGPIPE is asynchronous, we can't decide which smalltalk process
       
   356      should handle BrokenPipeSignal. So the system doesn't raise 
       
   357      BrokenPipeSignal for SIGPIPE any longer."
   334 
   358 
   335     ^ BrokenPipeSignal
   359     ^ BrokenPipeSignal
       
   360 
       
   361     "Modified: 24.9.1997 / 09:43:23 / stefan"
   336 ! !
   362 ! !
   337 
   363 
   338 !PipeStream methodsFor:'accessing'!
   364 !PipeStream methodsFor:'accessing'!
   339 
   365 
   340 commandString
   366 commandString
   616 ! !
   642 ! !
   617 
   643 
   618 !PipeStream class methodsFor:'documentation'!
   644 !PipeStream class methodsFor:'documentation'!
   619 
   645 
   620 version
   646 version
   621     ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.63 1997-09-23 04:59:39 cg Exp $'
   647     ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.64 1997-09-24 15:11:32 stefan Exp $'
   622 ! !
   648 ! !
   623 PipeStream initialize!
   649 PipeStream initialize!