AbstractOperatingSystem.st
changeset 3929 97dbb77fdf79
parent 3927 028ca7c70ac9
child 3942 52b6ed227424
--- a/AbstractOperatingSystem.st	Thu Nov 12 14:53:34 1998 +0100
+++ b/AbstractOperatingSystem.st	Thu Nov 12 14:54:14 1998 +0100
@@ -712,23 +712,211 @@
 !
 
 exec:aCommandPath withArguments:argArray
-    "execute the unix command specified by the argument, aCommandPath, with
+    "execute the OS command specified by the argument, aCommandPath, with
      arguments in argArray (no arguments, if nil).
      If successful, this method does NOT return and smalltalk is gone.
      If not successful, it does return. 
      Can be used on UNIX with fork or on other systems to chain to another program."
 
-    self exec:aCommandPath 
-           withArguments:argArray 
-           fileDescriptors:nil
-           closeDescriptors:nil 
-           fork:false 
-           newPgrp:false
-           inDirectory:nil
+    ^ self 
+        exec:aCommandPath 
+        withArguments:argArray
+        environment:nil
+        fileDescriptors:nil
+        closeDescriptors:nil 
+        fork:false 
+        newPgrp:false
+        inDirectory:nil
 
     "/ never reached ...
 
-    "Modified: / 10.11.1998 / 20:57:02 / cg"
+    "Modified: / 12.11.1998 / 14:44:26 / cg"
+!
+
+exec:aCommandPath withArguments:argColl environment:env fileDescriptors:fdColl closeDescriptors:closeFdColl fork:doFork newPgrp:newPgrp 
+    "Internal lowLevel entry for combined fork & exec;
+
+     If fork is false (chain a command):
+         execute the OS command specified by the argument, aCommandPath, with
+         arguments in argArray (no arguments, if nil).
+         If successful, this method does not return and smalltalk is gone.
+         If not successful, it does return.
+         Normal use is with forkForCommand.
+
+     If fork is true (subprocess command execution):
+        fork a child to do the above.
+        The process id of the child process is returned; nil if the fork failed.
+
+     fdArray contains the filedescriptors, to be used for the child (if fork is true).
+        fdArray[1] = 15 -> use fd 15 as stdin.
+        If an element of the array is set to nil, the corresponding filedescriptor
+        will be closed for the child.
+        fdArray[0] == StdIn for child
+        fdArray[1] == StdOut for child
+        fdArray[2] == StdErr for child
+        on VMS, these must be channels as returned by createMailBox.
+
+     closeFdArray contains descriptors that will be closed in the subprocess.
+        closeDescriptors are ignored in the WIN32 & VMS versions.
+
+     If newPgrp is true, the subprocess will be established in a new process group.
+        The processgroup will be equal to id.
+        newPgrp is not used on WIN32 and VMS systems.
+
+     env specifies environment variables which are passed differently from
+     the current environment. If non-nil, it must be a dictionary providing
+     key-value pairs for changed/added environment variables.
+     To pass a variable as empty (i.e. unset), pass a nil value.
+
+     Notice: this used to be two separate ST-methods; however, in order to use
+            vfork on some machines, it had to be merged into one, to avoid write
+            accesses to ST/X memory from the vforked-child.
+            The code below only does read accesses."
+
+    ^ self
+        exec:aCommandPath 
+        withArguments:argColl 
+        environment:env 
+        fileDescriptors:fdColl 
+        closeDescriptors:closeFdColl 
+        fork:doFork
+        newPgrp:newPgrp 
+        inDirectory:nil
+
+    "
+     |id|
+
+     id := OperatingSystem fork.
+     id == 0 ifTrue:[
+        'I am the child'.
+        OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp').
+        'not reached'.
+     ]
+    "
+    "
+     |id|
+
+     id := OperatingSystem fork.
+     id == 0 ifTrue:[
+        'I am the child'.
+        OperatingSystem
+           exec:'/bin/sh'
+           withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2').
+        'not reached'.
+     ].
+     id printNL.
+     (Delay forSeconds:3.5) wait.
+     'killing ...' printNL.
+     OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
+     OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
+    "
+
+    "Modified: / 20.7.1998 / 18:24:54 / cg"
+    "Created: / 12.11.1998 / 14:48:25 / cg"
+!
+
+exec:aCommandPath withArguments:argArray environment:env fileDescriptors:fds closeDescriptors:closeFds fork:doFork newPgrp:newGrp inDirectory:aDirectory
+    "execute an OS command"
+
+    ^ self subclassResponsibility
+
+    "Created: / 12.11.1998 / 14:46:15 / cg"
+!
+
+exec:aCommandPath withArguments:argArray fileDescriptors:fdArray closeDescriptors:closeFdArray fork:doFork newPgrp:newPgrp
+    "combined fork & exec;
+     If fork is false (chain a command):
+         execute the OS command specified by the argument, aCommandPath, with
+         arguments in argArray (no arguments, if nil).
+         If successful, this method does not return and smalltalk is gone.
+         If not successful, it does return.
+         Normal use is with forkForCommand.
+
+     If fork is true (subprocess command execution):
+        fork a child to do the above.
+        The process id of the child process is returned; nil if the fork failed.
+
+     fdArray contains the filedescriptors, to be used for the child (if fork is true).
+        fdArray[1] = 15 -> use fd 15 as stdin.
+        If an element of the array is set to nil, the corresponding filedescriptor
+        will be closed for the child.
+        fdArray[0] == StdIn for child
+        fdArray[1] == StdOut for child
+        fdArray[2] == StdErr for child
+        on VMS, these must be channels as returned by createMailBox.
+
+     closeFdArray contains descriptors that will be closed in the subprocess.
+        closeDescriptors are ignored in the WIN32 & VMS versions.
+
+     NOTE that in WIN32 the fds are HANDLES!!
+
+     If newPgrp is true, the subprocess will be established in a new process group.
+        The processgroup will be equal to id.
+        newPgrp is not used on WIN32 and VMS systems.
+
+     Notice: this used to be two separate ST-methods; however, in order to use
+            vfork on some machines, it had to be merged into one, to avoid write
+            accesses to ST/X memory from the vforked-child.
+            The code below only does read accesses."
+
+    ^ self
+        exec:aCommandPath 
+        withArguments:argArray
+        environment:nil 
+        fileDescriptors:fdArray 
+        closeDescriptors:closeFdArray
+        fork:doFork 
+        newPgrp:newPgrp
+        inDirectory:nil
+
+    "
+     |id|
+
+     id := OperatingSystem fork.
+     id == 0 ifTrue:[
+        'I am the child'.
+        OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp').
+        'not reached'.
+     ]
+    "
+    "
+     |id|
+
+     id := OperatingSystem fork.
+     id == 0 ifTrue:[
+        'I am the child'.
+        OperatingSystem
+           exec:'/bin/sh'
+           withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2').
+        'not reached'.
+     ].
+     id printNL.
+     (Delay forSeconds:3.5) wait.
+     'killing ...' printNL.
+     OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id.
+     OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
+    "
+
+    "Modified: / 12.11.1998 / 14:49:03 / cg"
+    "Created: / 12.11.1998 / 14:49:07 / cg"
+!
+
+exec:aCommandPath withArguments:argArray fileDescriptors:fdArray closeDescriptors:closeFdArray fork:doFork newPgrp:newPgrp inDirectory:aDirectory
+    "Internal lowLevel entry for combined fork & exec for WIN32.
+     Not needed with Unix"
+
+    ^ self
+        exec:aCommandPath 
+        withArguments:argArray 
+        environment:nil
+        fileDescriptors:fdArray
+        closeDescriptors:closeFdArray 
+        fork:doFork 
+        newPgrp:newPgrp
+        inDirectory:aDirectory
+
+    "Modified: / 12.11.1998 / 14:47:58 / cg"
+    "Created: / 12.11.1998 / 14:49:18 / cg"
 !
 
 exec:aCommandPath withArguments:argArray fork:doFork
@@ -737,13 +925,15 @@
      from/to whatever terminal device ST/X was started
      (typically, the xterm window)"
 
-    ^ self exec:aCommandPath 
-           withArguments:argArray 
-           fileDescriptors:nil
-           closeDescriptors:nil 
-           fork:doFork 
-           newPgrp:false
-           inDirectory:nil
+    ^ self 
+        exec:aCommandPath 
+        withArguments:argArray 
+        environment:nil
+        fileDescriptors:nil
+        closeDescriptors:nil 
+        fork:doFork 
+        newPgrp:false
+        inDirectory:nil
 
     "
      |id|
@@ -779,7 +969,7 @@
     "
 
     "Modified: / 15.7.1997 / 15:54:32 / stefan"
-    "Modified: / 10.11.1998 / 20:44:59 / cg"
+    "Modified: / 12.11.1998 / 14:44:46 / cg"
 !
 
 exec:aCommandPath withArguments:argArray fork:doFork inDirectory:aDirectory
@@ -788,24 +978,27 @@
      from/to whatever terminal device ST/X was started
      (typically, the xterm window)"
 
-    ^ self exec:aCommandPath
-	   withArguments:argArray
-	   fileDescriptors:nil
-	   closeDescriptors:nil
-	   fork:doFork 
-	   newPgrp:false
-	   inDirectory:aDirectory
+    ^ self 
+        exec:aCommandPath
+        withArguments:argArray
+        environment:nil
+        fileDescriptors:nil
+        closeDescriptors:nil
+        fork:doFork 
+        newPgrp:false
+        inDirectory:aDirectory
+
     "
      |id|
 
      id := OperatingSystem fork.
      id == 0 ifTrue:[
-	'I am the child'.
-	OperatingSystem 
-	    exec:'/bin/ls' 
-	    withArguments:#('ls' '/tmp')
-	    fork:false.
-	'not reached'.
+        'I am the child'.
+        OperatingSystem 
+            exec:'/bin/ls' 
+            withArguments:#('ls' '/tmp')
+            fork:false.
+        'not reached'.
      ]
     "
 
@@ -814,12 +1007,12 @@
 
      id := OperatingSystem fork.
      id == 0 ifTrue:[
-	'I am the child'.
-	OperatingSystem 
-	    exec:'/bin/sh' 
-	    withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2')
-	    fork:false.
-	'not reached'.
+        'I am the child'.
+        OperatingSystem 
+            exec:'/bin/sh' 
+            withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2')
+            fork:false.
+        'not reached'.
      ].
      id printNL.
      (Delay forSeconds:3.5) wait.
@@ -828,8 +1021,9 @@
      OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id
     "
 
-    "Created: 28.1.1998 / 14:14:03 / md"
-    "Modified: 28.1.1998 / 14:14:45 / md"
+    "Created: / 28.1.1998 / 14:14:03 / md"
+    "Modified: / 28.1.1998 / 14:14:45 / md"
+    "Modified: / 12.11.1998 / 14:45:06 / cg"
 !
 
 executableFileExtensions
@@ -3450,6 +3644,6 @@
 !AbstractOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.10 1998-11-11 15:09:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.11 1998-11-12 13:54:14 cg Exp $'
 ! !
 AbstractOperatingSystem initialize!