*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Tue, 29 Apr 1997 16:44:54 +0200
changeset 2598 519202e09350
parent 2597 ff5b82869b64
child 2599 e9d0af498464
*** empty log message ***
PipeStr.st
PipeStream.st
--- a/PipeStr.st	Tue Apr 29 16:39:58 1997 +0200
+++ b/PipeStr.st	Tue Apr 29 16:44:54 1997 +0200
@@ -343,7 +343,8 @@
     "open a pipe to the unix command in commandString; 
      mode may be 'r' or 'w'"
 
-    |blocked pipeFdArray execFdArray execFd myFd|
+    |blocked pipeFdArray execFdArray execFd myFd osType
+     shellPath shellArgs|
 
     filePointer notNil ifTrue:[
         "the pipe was already open ...
@@ -370,28 +371,50 @@
         myFd := pipeFdArray at:2.
     ].
 
+    osType := OperatingSystem getOSType.
+    (osType sameAs: 'win32') ifTrue:[
+	shellPath := 'C:\WINNT\System32\cmd /c'.
+	shellArgs := aCommandString.
+    ] ifFalse:[
+	shellPath := '/bin/sh'.
+	shellArgs := Array with:'sh' with:'-c' with:aCommandString.
+    ].
+
+    "/ must block here, to avoid races due to early finishing
+    "/ subprocesses ...
+
     blocked := OperatingSystem blockInterrupts.
-    pid := Processor monitor:[
-        OperatingSystem exec:'/bin/sh'
-               withArguments:(Array with:'sh' with:'-c' with:aCommandString)
-               fileDescriptors:execFdArray
-               closeDescriptors:(Array with:myFd)
-               fork:true
-               newPgrp:true.    
-    ] action:[ :status |
-        status stillAlive ifFalse:[
-            exitStatus := status.
-            pid := nil.
-            exitSema signal.
-        ].
-    ].
+
+    pid := Processor 
+	       monitor:[
+	          OperatingSystem 
+		      exec:shellPath
+                      withArguments:shellArgs
+                      fileDescriptors:execFdArray
+		      closeDescriptors:(Array with:myFd)
+                      fork:true
+		      newPgrp:true.
+	       ]
+	       action:[:status |
+                  status stillAlive ifFalse:[
+		      exitStatus := status.
+                      pid := nil.
+                      exitSema signal.
+	          ].
+               ].
+
     OperatingSystem closeFd:execFd.
     pid notNil ifTrue:[
-        self setFileDescriptor:myFd mode:mode.
+        (osType sameAs: 'win32') ifTrue:[
+            self setFileHandle:myFd mode:mode
+	] ifFalse:[
+            self setFileDescriptor:myFd mode:mode.
+	]
     ] ifFalse:[
         lastErrorNumber := OperatingSystem currentErrorNumber.
         OperatingSystem closeFd:myFd.
     ].
+
     blocked ifFalse:[
         OperatingSystem unblockInterrupts
     ].
@@ -440,6 +463,6 @@
 !PipeStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/PipeStr.st,v 1.52 1997-04-29 14:39:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/PipeStr.st,v 1.53 1997-04-29 14:44:54 cg Exp $'
 ! !
 PipeStream initialize!
--- a/PipeStream.st	Tue Apr 29 16:39:58 1997 +0200
+++ b/PipeStream.st	Tue Apr 29 16:44:54 1997 +0200
@@ -343,7 +343,8 @@
     "open a pipe to the unix command in commandString; 
      mode may be 'r' or 'w'"
 
-    |blocked pipeFdArray execFdArray execFd myFd|
+    |blocked pipeFdArray execFdArray execFd myFd osType
+     shellPath shellArgs|
 
     filePointer notNil ifTrue:[
         "the pipe was already open ...
@@ -370,28 +371,50 @@
         myFd := pipeFdArray at:2.
     ].
 
+    osType := OperatingSystem getOSType.
+    (osType sameAs: 'win32') ifTrue:[
+	shellPath := 'C:\WINNT\System32\cmd /c'.
+	shellArgs := aCommandString.
+    ] ifFalse:[
+	shellPath := '/bin/sh'.
+	shellArgs := Array with:'sh' with:'-c' with:aCommandString.
+    ].
+
+    "/ must block here, to avoid races due to early finishing
+    "/ subprocesses ...
+
     blocked := OperatingSystem blockInterrupts.
-    pid := Processor monitor:[
-        OperatingSystem exec:'/bin/sh'
-               withArguments:(Array with:'sh' with:'-c' with:aCommandString)
-               fileDescriptors:execFdArray
-               closeDescriptors:(Array with:myFd)
-               fork:true
-               newPgrp:true.    
-    ] action:[ :status |
-        status stillAlive ifFalse:[
-            exitStatus := status.
-            pid := nil.
-            exitSema signal.
-        ].
-    ].
+
+    pid := Processor 
+	       monitor:[
+	          OperatingSystem 
+		      exec:shellPath
+                      withArguments:shellArgs
+                      fileDescriptors:execFdArray
+		      closeDescriptors:(Array with:myFd)
+                      fork:true
+		      newPgrp:true.
+	       ]
+	       action:[:status |
+                  status stillAlive ifFalse:[
+		      exitStatus := status.
+                      pid := nil.
+                      exitSema signal.
+	          ].
+               ].
+
     OperatingSystem closeFd:execFd.
     pid notNil ifTrue:[
-        self setFileDescriptor:myFd mode:mode.
+        (osType sameAs: 'win32') ifTrue:[
+            self setFileHandle:myFd mode:mode
+	] ifFalse:[
+            self setFileDescriptor:myFd mode:mode.
+	]
     ] ifFalse:[
         lastErrorNumber := OperatingSystem currentErrorNumber.
         OperatingSystem closeFd:myFd.
     ].
+
     blocked ifFalse:[
         OperatingSystem unblockInterrupts
     ].
@@ -440,6 +463,6 @@
 !PipeStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.52 1997-04-29 14:39:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.53 1997-04-29 14:44:54 cg Exp $'
 ! !
 PipeStream initialize!