comment
authorClaus Gittinger <cg@exept.de>
Tue, 25 Jul 2000 16:13:57 +0200
changeset 5481 680d6de80808
parent 5480 92eb8594f437
child 5482 433983048ce8
comment
PipeStream.st
--- a/PipeStream.st	Tue Jul 25 12:47:43 2000 +0200
+++ b/PipeStream.st	Tue Jul 25 16:13:57 2000 +0200
@@ -516,22 +516,28 @@
 
 openPipeFor:aCommandString withMode:rwMode errorDisposition:err inDirectory:aDirectory
     "open a pipe to the OS command in commandString; 
-     rwMode may be 'r' or 'w'"
+     rwMode may be 'r' or 'w'.
+     errorDisposition controls where the stdErr output should go,
+     and may be one of #discard, #inline or #stderr (default).
+     #discard causes stderr to be discarded (/dev/null), 
+     #inline causes it to be written to smalltalks own stdout and
+     #stderr causes it to be written to smalltalks own stderr.
+     Nil is treated like #stderr"
 
     |blocked pipeFdArray execFdArray execFd myFd shellAndArgs
      shellPath shellArgs closeFdArray mbx mbxName 
      realCmd execDirectory tmpComFile nullOutput|
 
     filePointer notNil ifTrue:[
-	"the pipe was already open ...
-	 this should (can) not happen."
-	^ self errorAlreadyOpen
+        "the pipe was already open ...
+         this should (can) not happen."
+        ^ self errorAlreadyOpen
     ].
 
     rwMode = 'r' ifTrue:[
-	mode := #readonly. didWrite := false.
+        mode := #readonly. didWrite := false.
     ] ifFalse:[
-	mode := #writeonly. didWrite := true.
+        mode := #writeonly. didWrite := true.
     ].
 
     lastErrorNumber := nil.
@@ -542,79 +548,79 @@
     execDirectory := aDirectory.
 
     OperatingSystem isVMSlike ifTrue:[
-	"/
-	"/ the generated COM-file includes a 'set default'
-	"/
-	tmpComFile := OperatingSystem createCOMFileForVMSCommand:aCommandString in:aDirectory.
-	realCmd := '@' , tmpComFile osName.
-	execDirectory := nil.
+        "/
+        "/ the generated COM-file includes a 'set default'
+        "/
+        tmpComFile := OperatingSystem createCOMFileForVMSCommand:aCommandString in:aDirectory.
+        realCmd := '@' , tmpComFile osName.
+        execDirectory := nil.
 
-	mbx := OperatingSystem createMailBox.
-	mbx isNil ifTrue:[
-	    lastErrorNumber := OperatingSystem currentErrorNumber.
-	    tmpComFile delete.
-	    ^ self openError
-	].
-	mbxName := OperatingSystem mailBoxNameOf:mbx.
+        mbx := OperatingSystem createMailBox.
+        mbx isNil ifTrue:[
+            lastErrorNumber := OperatingSystem currentErrorNumber.
+            tmpComFile delete.
+            ^ self openError
+        ].
+        mbxName := OperatingSystem mailBoxNameOf:mbx.
 
-	"/ 'mailBox is ' print. mbx print. ' name is ' print. mbxName printCR.
-	shellPath := ''.
-	shellArgs := realCmd.
+        "/ 'mailBox is ' print. mbx print. ' name is ' print. mbxName printCR.
+        shellPath := ''.
+        shellArgs := realCmd.
 
-	rwMode = 'r' ifTrue:[
-	    execFdArray := Array with:0 with:mbx with:2.
-	    (err == #inline or:[err == #stdout]) ifTrue:[
-		execFdArray at:3 put:mbx
-	    ]
-	] ifFalse:[
-	    execFdArray := Array with:mbx with:1 with:2.
-	    (err == #inline or:[err == #stdout]) ifTrue:[
-		execFdArray at:3 put:1
-	    ]
-	].
-	closeFdArray := nil.
+        rwMode = 'r' ifTrue:[
+            execFdArray := Array with:0 with:mbx with:2.
+            (err == #inline or:[err == #stdout]) ifTrue:[
+                execFdArray at:3 put:mbx
+            ]
+        ] ifFalse:[
+            execFdArray := Array with:mbx with:1 with:2.
+            (err == #inline or:[err == #stdout]) ifTrue:[
+                execFdArray at:3 put:1
+            ]
+        ].
+        closeFdArray := nil.
     ] ifFalse:[
-	OperatingSystem isUNIXlike ifTrue:[
-	    aDirectory notNil ifTrue:[
-		"/ unix - prepend a 'cd' to the command
-		realCmd := 'cd ' , aDirectory asFilename name, '; ' , aCommandString.
-	    ] ifFalse:[
-		realCmd := aCommandString
-	    ].
-	    execDirectory := nil.
-	].
+        OperatingSystem isUNIXlike ifTrue:[
+            aDirectory notNil ifTrue:[
+                "/ unix - prepend a 'cd' to the command
+                realCmd := 'cd ' , aDirectory asFilename name, '; ' , aCommandString.
+            ] ifFalse:[
+                realCmd := aCommandString
+            ].
+            execDirectory := nil.
+        ].
 
-	pipeFdArray := OperatingSystem makePipe.
-	pipeFdArray isNil ifTrue:[
-	    lastErrorNumber := OperatingSystem currentErrorNumber.
-	    ^ self openError
-	].
+        pipeFdArray := OperatingSystem makePipe.
+        pipeFdArray isNil ifTrue:[
+            lastErrorNumber := OperatingSystem currentErrorNumber.
+            ^ self openError
+        ].
 
-	shellAndArgs := OperatingSystem commandAndArgsForOSCommand:realCmd.
-	shellPath := shellAndArgs at:1.
-	shellArgs := shellAndArgs at:2.
+        shellAndArgs := OperatingSystem commandAndArgsForOSCommand:realCmd.
+        shellPath := shellAndArgs at:1.
+        shellArgs := shellAndArgs at:2.
 
-	rwMode = 'r' ifTrue:[
-	    myFd := pipeFdArray at:1.
-	    execFd := pipeFdArray at:2.
-	    execFdArray := Array with:0 with:execFd with:2.
-	    (err == #inline or:[err == #stdout]) ifTrue:[
-		execFdArray at:3 put:execFd
-	    ]
-	] ifFalse:[
-	    myFd := pipeFdArray at:2.
-	    execFd := pipeFdArray at:1.
-	    execFdArray := Array with:execFd with:1 with:2.
-	    (err == #inline or:[err == #stdout]) ifTrue:[
-		execFdArray at:3 put:1
-	    ]
-	].
-	closeFdArray := Array with:myFd.
+        rwMode = 'r' ifTrue:[
+            myFd := pipeFdArray at:1.
+            execFd := pipeFdArray at:2.
+            execFdArray := Array with:0 with:execFd with:2.
+            (err == #inline or:[err == #stdout]) ifTrue:[
+                execFdArray at:3 put:execFd
+            ]
+        ] ifFalse:[
+            myFd := pipeFdArray at:2.
+            execFd := pipeFdArray at:1.
+            execFdArray := Array with:execFd with:1 with:2.
+            (err == #inline or:[err == #stdout]) ifTrue:[
+                execFdArray at:3 put:1
+            ]
+        ].
+        closeFdArray := Array with:myFd.
     ].
 
     err == #discard ifTrue:[
-	nullOutput := Filename nullDevice writeStream.
-	execFdArray at:3 put:nullOutput fileDescriptor
+        nullOutput := Filename nullDevice writeStream.
+        execFdArray at:3 put:nullOutput fileDescriptor
     ].
 
     "/ must block here, to avoid races due to early finishing
@@ -623,69 +629,69 @@
     blocked := OperatingSystem blockInterrupts.
 
     pid := Processor 
-	       monitor:[
-		  OperatingSystem 
-		      exec:shellPath
-		      withArguments:shellArgs
-		      fileDescriptors:execFdArray
-		      closeDescriptors:closeFdArray
-		      fork:true
-		      newPgrp:true
-		      inDirectory:execDirectory.
-	       ]
-	       action:[:status |
-		  status stillAlive ifFalse:[
-		      exitStatus := status.
-		      OperatingSystem closePid:pid.
-		      pid := nil.
-		      exitSema signal.
-		  ].
-	       ].
+               monitor:[
+                  OperatingSystem 
+                      exec:shellPath
+                      withArguments:shellArgs
+                      fileDescriptors:execFdArray
+                      closeDescriptors:closeFdArray
+                      fork:true
+                      newPgrp:true
+                      inDirectory:execDirectory.
+               ]
+               action:[:status |
+                  status stillAlive ifFalse:[
+                      exitStatus := status.
+                      OperatingSystem closePid:pid.
+                      pid := nil.
+                      exitSema signal.
+                  ].
+               ].
 
     OperatingSystem isVMSlike ifFalse:[
-	OperatingSystem closeFd:execFd.
+        OperatingSystem closeFd:execFd.
     ].
 
     nullOutput notNil ifTrue:[
-	nullOutput close
+        nullOutput close
     ].
 
     pid notNil ifTrue:[
-	OperatingSystem isVMSlike ifTrue:[
-	    "/
-	    "/ reopen the mailbox as a file ...
-	    "/
-	    mbxName := OperatingSystem mailBoxNameOf:mbx.
-	    mbxName notNil ifTrue:[
-		super open:mbxName withMode:rwMode.
-		exitAction := [tmpComFile delete].
-	    ].
-	] ifFalse:[
-	    self setFileDescriptor:myFd mode:rwMode.
-	]
+        OperatingSystem isVMSlike ifTrue:[
+            "/
+            "/ reopen the mailbox as a file ...
+            "/
+            mbxName := OperatingSystem mailBoxNameOf:mbx.
+            mbxName notNil ifTrue:[
+                super open:mbxName withMode:rwMode.
+                exitAction := [tmpComFile delete].
+            ].
+        ] ifFalse:[
+            self setFileDescriptor:myFd mode:rwMode.
+        ]
     ] ifFalse:[
-	lastErrorNumber := OperatingSystem currentErrorNumber.
-	OperatingSystem isVMSlike ifTrue:[
-	    OperatingSystem destroyMailBox:mbx.
-	    tmpComFile delete.
-	] ifFalse:[
-	    OperatingSystem closeFd:myFd.
-	].
+        lastErrorNumber := OperatingSystem currentErrorNumber.
+        OperatingSystem isVMSlike ifTrue:[
+            OperatingSystem destroyMailBox:mbx.
+            tmpComFile delete.
+        ] ifFalse:[
+            OperatingSystem closeFd:myFd.
+        ].
     ].
 
     blocked ifFalse:[
-	OperatingSystem unblockInterrupts
+        OperatingSystem unblockInterrupts
     ].
 
     lastErrorNumber notNil ifTrue:[
-	"
-	 the pipe open failed for some reason ...
-	 ... this may be either due to an invalid command string,
-	 or due to the system running out of memory (when forking
-	 the unix process)
-	"
-	exitAction value.
-	^ self openError
+        "
+         the pipe open failed for some reason ...
+         ... this may be either due to an invalid command string,
+         or due to the system running out of memory (when forking
+         the unix process)
+        "
+        exitAction value.
+        ^ self openError
     ].
 
     commandString := realCmd.
@@ -710,6 +716,6 @@
 !PipeStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.85 2000-07-11 10:24:59 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.86 2000-07-25 14:13:57 cg Exp $'
 ! !
 PipeStream initialize!