class: AbstractOperatingSystem
authorClaus Gittinger <cg@exept.de>
Tue, 06 May 2014 11:51:07 +0200
changeset 16395 6f0be1e7811f
parent 16394 a662e916316c
child 16396 4896e6f5ffda
class: AbstractOperatingSystem added: #executeCommand:inputFrom:outputTo:errorTo:environment:onError: comment/format in: #decodePath:
AbstractOperatingSystem.st
--- a/AbstractOperatingSystem.st	Tue May 06 11:05:46 2014 +0200
+++ b/AbstractOperatingSystem.st	Tue May 06 11:51:07 2014 +0200
@@ -1457,6 +1457,72 @@
 	onError:aBlock
 !
 
+executeCommand:aCommandString inputFrom:anInStream outputTo:anOutStream errorTo:anErrStream environment:env onError:aBlock
+    "execute the unix command specified by the argument, aCommandString.
+     The commandString is passed to a shell for execution - see the description of
+     'sh -c' in your UNIX manual.
+     Return true if successful, the value from aBlock if not.
+     If not successfull, aBlock is called with an OsProcessStatus
+     (containing the exit status) as argument."
+
+    ^ self
+        executeCommand:aCommandString
+        inputFrom:anInStream
+        outputTo:anOutStream
+        errorTo:anErrStream
+        auxFrom:nil
+        environment:env
+        inDirectory:nil
+        lineWise:false
+        onError:aBlock
+
+    "
+        OperatingSystem
+            executeCommand:'dir'
+            inputFrom:nil
+            outputTo:nil
+            errorTo:nil
+            onError:[:status | Transcript flash]
+
+        OperatingSystem
+            executeCommand:'foo'
+            inputFrom:nil
+            outputTo:nil
+            errorTo:nil
+            onError:[:status | Transcript flash]
+    "
+    "
+        |outStr errStr|
+
+        outStr := '' writeStream.
+        errStr := '' writeStream.
+        OperatingSystem
+            executeCommand:'ls'
+            inputFrom:nil
+            outputTo:outStr
+            errorTo:errStr
+            onError:[:status | Transcript flash].
+        Transcript show:'out:'; showCR:outStr contents.
+        Transcript show:'err:'; showCR:errStr contents.
+    "
+    "
+        |outStr errStr|
+
+        outStr := '' writeStream.
+        errStr := '' writeStream.
+        OperatingSystem
+            executeCommand:'ls /fooBar'
+            inputFrom:nil
+            outputTo:outStr
+            errorTo:errStr
+            onError:[:status | Transcript flash].
+        Transcript show:'out:'; showCR:outStr contents.
+        Transcript show:'err:'; showCR:errStr contents.
+    "
+
+    "Modified: / 10.11.1998 / 20:51:39 / cg"
+!
+
 executeCommand:aCommandString inputFrom:inputStreamOrNil outputTo:outStreamOrNil errorTo:errStreamOrNil inDirectory:aDirectory
     "much like #executeCommand:, but changes the current directory
      for the command. Since this is OS specific, use this instead of
@@ -4249,12 +4315,12 @@
 
 !AbstractOperatingSystem class methodsFor:'path queries'!
 
-decodePath:encodedPathName
-    "decode the pathName as returned by system calls.
-     E.g. linux system calls return sigle byte strings only,
-     so the pathName has been UTF-8 decoded."
-
-    ^ encodedPathName
+decodePath:encodedPathNameOrOutputLine
+    "decode the encodedPathNameOrOutputLine as returned by system calls or output by system commands.
+     E.g. linux system calls return single byte strings only,
+     so pathNames have been UTF-8 encoded."
+
+    ^ encodedPathNameOrOutputLine
 !
 
 defaultPackagePath
@@ -7358,11 +7424,11 @@
 !AbstractOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.256 2014-04-19 22:49:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.257 2014-05-06 09:51:07 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.256 2014-04-19 22:49:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.257 2014-05-06 09:51:07 cg Exp $'
 ! !