class: PipeStream
authorClaus Gittinger <cg@exept.de>
Sat, 14 Jun 2014 11:22:57 +0200
changeset 16579 3d51a7434f06
parent 16578 0ed0b88c0bc8
child 16580 3ce6c6d0fac2
class: PipeStream added: #outputFromCommand:
PipeStream.st
--- a/PipeStream.st	Sat Jun 14 11:09:56 2014 +0200
+++ b/PipeStream.st	Sat Jun 14 11:22:57 2014 +0200
@@ -416,6 +416,29 @@
     "Modified: 24.9.1997 / 09:43:23 / stefan"
 ! !
 
+!PipeStream class methodsFor:'utilities'!
+
+outputFromCommand:aCommand
+    "open a pipe reading from aCommand and return the complete output as a string.
+     If the command cannot be executed, return nil"
+
+    |p cmdOutput|
+
+    p := self readingFrom:aCommand.
+    p isNil ifTrue:[^ nil].
+
+    [
+        cmdOutput := p contentsAsString.
+    ] ensure:[
+        p close.
+    ].
+    ^ cmdOutput
+
+    "
+     PipeStream outputFromCommand:'ls -l'
+    "
+! !
+
 !PipeStream methodsFor:'accessing'!
 
 commandString
@@ -794,11 +817,11 @@
 !PipeStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.115 2014-04-15 14:06:51 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.116 2014-06-14 09:22:57 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.115 2014-04-15 14:06:51 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.116 2014-06-14 09:22:57 cg Exp $'
 ! !