--- a/PipeStream.st Sun May 20 15:36:39 2018 +0200
+++ b/PipeStream.st Sun May 20 15:46:55 2018 +0200
@@ -194,6 +194,63 @@
ExternalStream FileStream Socket
OperatingSystem
"
+!
+
+examples
+"
+ reading:
+ [exBegin]
+ |p output|
+
+ p := PipeStream readingFrom:'ls -l'.
+ output := p upToEnd.
+ p close.
+ Transcript showCR:output
+ [exEnd]
+
+ bidirectional:
+ [exBegin]
+ |p|
+
+ p := PipeStream bidirectionalFor:'sed -e s/Hello/Greetings/'.
+ p nextPutLine:'bla'; flush.
+ Transcript showCR:p nextLine.
+ p nextPutLine:'foo Hello'.
+ Transcript showCR:p nextLine.
+ p nextPutLine:'bar'.
+ Transcript showCR:p nextLine.
+ p close.
+ [exEnd]
+
+ error output is on my stderr:
+ [exBegin]
+ |p|
+
+ p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2'.
+ Transcript showCR:p upToEnd.
+ p close.
+ [exEnd]
+
+ error output is included:
+ [exBegin]
+ |p|
+
+ p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2' errorDisposition:#stdout.
+ Transcript showCR:p upToEnd.
+ p close.
+ [exEnd]
+
+ error output is separate:
+ [exBegin]
+ |p errStream|
+
+ errStream := '' writeStream.
+ p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2' errorDisposition:errStream.
+ Transcript showCR:'output:'; showCR:p upToEnd; cr.
+ p close.
+ Transcript showCR:'error:'; showCR:errStream contents; cr.
+ [exEnd]
+"
! !
!PipeStream class methodsFor:'initialization'!
@@ -418,6 +475,69 @@
"
!
+readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream
+ "create and return a new pipeStream which can read from the unix command
+ given by commandString.
+ errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
+ #discard causes stderr to be discarded (/dev/null),
+ #inline causes it to be merged into the PipeStream and
+ #stderr causes it to be written to smalltalk's own stderr.
+ a stream causes stderr to be sent to that stream (internal or external)
+ Nil is treated like #stderr"
+
+ ^ self
+ readingFrom:commandString
+ errorDisposition:errorDispositionSymbolOrStream
+ inDirectory:nil
+
+ "unix:
+ PipeStream readingFrom:'ls -l'.
+ "
+
+ "
+ |p|
+
+ p := PipeStream readingFrom:'ls -l'.
+ Transcript showCR:p nextLine.
+ p close
+ "
+
+
+ "
+ |p|
+
+ p := PipeStream readingFrom:'echo error >&2'.
+ Transcript showCR:p nextLine.
+ p close
+ "
+
+ "
+ |s|
+ s := PipeStream readingFrom:'sh -c sleep\ 600'.
+ (Delay forSeconds:2) wait.
+ s abortAndClose
+ "
+
+ "
+ |p|
+ p := PipeStream readingFrom:'dir'.
+ Transcript showCR:p nextLine.
+ p close
+ "
+
+ "Windows:
+ PipeStream readingFrom:'dir'.
+ "
+ "
+ |p|
+ p := PipeStream readingFrom:'dir'.
+ Transcript showCR:p nextLine.
+ p close
+ "
+
+ "Modified: 24.4.1996 / 09:09:25 / stefan"
+!
+
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream environment:aShellEnvironmentOrNil inDirectory:aDirectory
"similar to #readingFrom, but changes the directory while
executing the command. Use this if a command is to be