AbstractOperatingSystem.st
changeset 20325 d8c3fcfa6a72
parent 20322 92697560b556
child 20334 59e4b708273f
child 20345 68e5382ae472
equal deleted inserted replaced
20324:767fdd53f30a 20325:d8c3fcfa6a72
  1437      Nil stream args will execute the command connected to ST/X's standard input, output or
  1437      Nil stream args will execute the command connected to ST/X's standard input, output or
  1438      error resp. - i.e. usually, i/o will be from/to the terminal.
  1438      error resp. - i.e. usually, i/o will be from/to the terminal.
  1439 
  1439 
  1440      Set lineWise to true, if both error and output is sent to the same stream
  1440      Set lineWise to true, if both error and output is sent to the same stream
  1441      and you don't want lines to be mangled. Set lineWise = false to
  1441      and you don't want lines to be mangled. Set lineWise = false to
  1442      avoid blocking on pipes"
  1442      avoid blocking on pipes.
       
  1443 
       
  1444      Special for windows:
       
  1445         you can control (have to - sigh) if a window should be shown for the command or not.
       
  1446         This is the OS's H_SHOWWINDOW argument.
       
  1447         If you pass nil as showWindow-argument, the OS's default is used for the particular
       
  1448         command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
       
  1449         executables will not.
       
  1450         However, some command-line executables show a window, even if they should not.
       
  1451         (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
       
  1452          a shell command opens a cmd-window, whereas in windows7 it did not)
       
  1453         In this case, pass an explicit false argument to suppress it.
       
  1454         This argument is ignored on Unix systems.
       
  1455         See examples below."
  1443 
  1456 
  1444     |pid exitStatus sema pIn pOut pErr pAux externalInStream externalOutStream externalErrStream externalAuxStream
  1457     |pid exitStatus sema pIn pOut pErr pAux externalInStream externalOutStream externalErrStream externalAuxStream
  1445      shuffledInStream shuffledOutStream shuffledErrStream shuffledAuxStream
  1458      shuffledInStream shuffledOutStream shuffledErrStream shuffledAuxStream
  1446      inputShufflerProcess outputShufflerProcess errorShufflerProcess auxShufflerProcess stopShufflers
  1459      inputShufflerProcess outputShufflerProcess errorShufflerProcess auxShufflerProcess stopShufflers
  1447      inStreamToClose outStreamToClose errStreamToClose auxStreamToClose nullStream terminateLock
  1460      inStreamToClose outStreamToClose errStreamToClose auxStreamToClose nullStream terminateLock
  2107 !
  2120 !
  2108 
  2121 
  2109 executeCommand:aCommandString outputTo:outStreamOrNil errorTo:errStreamOrNil inDirectory:aDirectory showWindow:showWindowBooleanOrNil
  2122 executeCommand:aCommandString outputTo:outStreamOrNil errorTo:errStreamOrNil inDirectory:aDirectory showWindow:showWindowBooleanOrNil
  2110     "much like #executeCommand:, but changes the current directory
  2123     "much like #executeCommand:, but changes the current directory
  2111      for the command. Since this is OS specific, use this instead of
  2124      for the command. Since this is OS specific, use this instead of
  2112      hardwiring any 'cd ..' command strings into your applictions."
  2125      hardwiring any 'cd ..' command strings into your applictions.
       
  2126 
       
  2127      Special for windows:
       
  2128         you can control (have to - sigh) if a window should be shown for the command or not.
       
  2129         This is the OS's H_SHOWWINDOW argument.
       
  2130         If you pass nil as showWindow-argument, the OS's default is used for the particular
       
  2131         command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
       
  2132         executables will not.
       
  2133         However, some command-line executables show a window, even if they should not.
       
  2134         (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
       
  2135          a shell command opens a cmd-window, whereas in windows7 it did not)
       
  2136         In this case, pass an explicit false argument to suppress it.
       
  2137         This argument is ignored on Unix systems.
       
  2138         See examples below."
  2113 
  2139 
  2114      ^ self
  2140      ^ self
  2115         executeCommand:aCommandString
  2141         executeCommand:aCommandString
  2116         inputFrom:nil
  2142         inputFrom:nil
  2117         outputTo:outStreamOrNil
  2143         outputTo:outStreamOrNil
  2158      OperatingSystem executeCommand:'dir'
  2184      OperatingSystem executeCommand:'dir'
  2159     "
  2185     "
  2160 
  2186 
  2161     "Modified: / 20-01-1998 / 17:03:03 / md"
  2187     "Modified: / 20-01-1998 / 17:03:03 / md"
  2162     "Created: / 23-01-2012 / 14:07:50 / cg"
  2188     "Created: / 23-01-2012 / 14:07:50 / cg"
       
  2189 !
       
  2190 
       
  2191 executeCommand:aCommandString showWindow:aBooleanOrNil
       
  2192     "execute the OS command specified by the argument, aCommandString.
       
  2193      If aCommandString is a String, the commandString is passed to a shell for execution
       
  2194      - see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
       
  2195      If aCommandString is an Array, the first element is the command to be executed,
       
  2196      and the other elements are the arguments to the command. 
       
  2197      No shell is invoked in this case.
       
  2198      This blocks the current thread until the command has finished.
       
  2199      Return true if successful, false otherwise.
       
  2200 
       
  2201      Special for windows:
       
  2202         you can control (have to - sigh) if a window should be shown for the command or not.
       
  2203         This is the OS's H_SHOWWINDOW argument.
       
  2204         If you pass nil as showWindow-argument, the OS's default is used for the particular
       
  2205         command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
       
  2206         executables will not.
       
  2207         However, some command-line executables show a window, even if they should not.
       
  2208         (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
       
  2209          a shell command opens a cmd-window, whereas in windows7 it did not)
       
  2210         In this case, pass an explicit false argument to suppress it.
       
  2211         This argument is ignored on Unix systems.
       
  2212         See examples below.
       
  2213     "
       
  2214 
       
  2215      ^ self
       
  2216         executeCommand:aCommandString
       
  2217         inputFrom:nil
       
  2218         outputTo:nil
       
  2219         errorTo:nil
       
  2220         auxFrom:nil
       
  2221         environment:nil
       
  2222         inDirectory:nil
       
  2223         lineWise:false
       
  2224         showWindow:aBooleanOrNil
       
  2225         onError:[:status| false]
       
  2226 
       
  2227     "unix:
       
  2228 
       
  2229      OperatingSystem executeCommand:'sleep 30'.
       
  2230      OperatingSystem executeCommand:'pwd'.
       
  2231      OperatingSystem executeCommand:'ls -l'.
       
  2232      OperatingSystem executeCommand:'invalidCommand'.
       
  2233      OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'.
       
  2234     "
       
  2235 
       
  2236     "msdos:
       
  2237 
       
  2238      OperatingSystem executeCommand:'dir'
       
  2239      OperatingSystem executeCommand:'dir' showWindow:false
       
  2240      OperatingSystem executeCommand:'dir /w'
       
  2241     "
       
  2242 
       
  2243     "vms:
       
  2244 
       
  2245      OperatingSystem executeCommand:'dir'
       
  2246      OperatingSystem executeCommand:'purge'
       
  2247      OperatingSystem executeCommand:'cc foo.c'
       
  2248     "
       
  2249 
       
  2250     "Modified: / 7.1.1997 / 19:29:55 / stefan"
       
  2251     "Modified: / 10.11.1998 / 20:55:37 / cg"
  2163 !
  2252 !
  2164 
  2253 
  2165 getCommandOutputFrom:aCommand
  2254 getCommandOutputFrom:aCommand
  2166     "execute a simple command (such as hostname) and
  2255     "execute a simple command (such as hostname) and
  2167      return the commands first line of output as a string (forget stdErr).
  2256      return the commands first line of output as a string (forget stdErr).