AbstractOperatingSystem.st
changeset 20325 d8c3fcfa6a72
parent 20322 92697560b556
child 20334 59e4b708273f
child 20345 68e5382ae472
--- a/AbstractOperatingSystem.st	Thu Sep 01 18:04:52 2016 +0200
+++ b/AbstractOperatingSystem.st	Thu Sep 01 18:17:44 2016 +0200
@@ -1439,7 +1439,20 @@
 
      Set lineWise to true, if both error and output is sent to the same stream
      and you don't want lines to be mangled. Set lineWise = false to
-     avoid blocking on pipes"
+     avoid blocking on pipes.
+
+     Special for windows:
+        you can control (have to - sigh) if a window should be shown for the command or not.
+        This is the OS's H_SHOWWINDOW argument.
+        If you pass nil as showWindow-argument, the OS's default is used for the particular
+        command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
+        executables will not.
+        However, some command-line executables show a window, even if they should not.
+        (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
+         a shell command opens a cmd-window, whereas in windows7 it did not)
+        In this case, pass an explicit false argument to suppress it.
+        This argument is ignored on Unix systems.
+        See examples below."
 
     |pid exitStatus sema pIn pOut pErr pAux externalInStream externalOutStream externalErrStream externalAuxStream
      shuffledInStream shuffledOutStream shuffledErrStream shuffledAuxStream
@@ -2109,7 +2122,20 @@
 executeCommand:aCommandString outputTo:outStreamOrNil errorTo:errStreamOrNil inDirectory:aDirectory showWindow:showWindowBooleanOrNil
     "much like #executeCommand:, but changes the current directory
      for the command. Since this is OS specific, use this instead of
-     hardwiring any 'cd ..' command strings into your applictions."
+     hardwiring any 'cd ..' command strings into your applictions.
+
+     Special for windows:
+        you can control (have to - sigh) if a window should be shown for the command or not.
+        This is the OS's H_SHOWWINDOW argument.
+        If you pass nil as showWindow-argument, the OS's default is used for the particular
+        command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
+        executables will not.
+        However, some command-line executables show a window, even if they should not.
+        (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
+         a shell command opens a cmd-window, whereas in windows7 it did not)
+        In this case, pass an explicit false argument to suppress it.
+        This argument is ignored on Unix systems.
+        See examples below."
 
      ^ self
         executeCommand:aCommandString
@@ -2162,6 +2188,69 @@
     "Created: / 23-01-2012 / 14:07:50 / cg"
 !
 
+executeCommand:aCommandString showWindow:aBooleanOrNil
+    "execute the OS command specified by the argument, aCommandString.
+     If aCommandString is a String, the commandString is passed to a shell for execution
+     - see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
+     If aCommandString is an Array, the first element is the command to be executed,
+     and the other elements are the arguments to the command. 
+     No shell is invoked in this case.
+     This blocks the current thread until the command has finished.
+     Return true if successful, false otherwise.
+
+     Special for windows:
+        you can control (have to - sigh) if a window should be shown for the command or not.
+        This is the OS's H_SHOWWINDOW argument.
+        If you pass nil as showWindow-argument, the OS's default is used for the particular
+        command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
+        executables will not.
+        However, some command-line executables show a window, even if they should not.
+        (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
+         a shell command opens a cmd-window, whereas in windows7 it did not)
+        In this case, pass an explicit false argument to suppress it.
+        This argument is ignored on Unix systems.
+        See examples below.
+    "
+
+     ^ self
+        executeCommand:aCommandString
+        inputFrom:nil
+        outputTo:nil
+        errorTo:nil
+        auxFrom:nil
+        environment:nil
+        inDirectory:nil
+        lineWise:false
+        showWindow:aBooleanOrNil
+        onError:[:status| false]
+
+    "unix:
+
+     OperatingSystem executeCommand:'sleep 30'.
+     OperatingSystem executeCommand:'pwd'.
+     OperatingSystem executeCommand:'ls -l'.
+     OperatingSystem executeCommand:'invalidCommand'.
+     OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'.
+    "
+
+    "msdos:
+
+     OperatingSystem executeCommand:'dir'
+     OperatingSystem executeCommand:'dir' showWindow:false
+     OperatingSystem executeCommand:'dir /w'
+    "
+
+    "vms:
+
+     OperatingSystem executeCommand:'dir'
+     OperatingSystem executeCommand:'purge'
+     OperatingSystem executeCommand:'cc foo.c'
+    "
+
+    "Modified: / 7.1.1997 / 19:29:55 / stefan"
+    "Modified: / 10.11.1998 / 20:55:37 / cg"
+!
+
 getCommandOutputFrom:aCommand
     "execute a simple command (such as hostname) and
      return the commands first line of output as a string (forget stdErr).