#FEATURE
authorClaus Gittinger <cg@exept.de>
Sun, 20 Mar 2016 10:49:00 +0100
changeset 19377 fca073527bd3
parent 19376 5dc7266efb72
child 19378 93bf71d3fc81
#FEATURE class: Process added: #stderr #stdin #stdout #transcript provide those from thread-local-storage, to allow threads with redirected I/O
Process.st
--- a/Process.st	Fri Mar 18 10:29:20 2016 +0100
+++ b/Process.st	Sun Mar 20 10:49:00 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
@@ -2135,6 +2133,48 @@
     ^ aValue
 !
 
+stderr
+    "the processes stderr.
+     By default, this is Stderr, but it can be overwritten
+     (for example to redirect a thread's error output to some other place"
+     
+    ^ self environmentAt:#Stderr ifAbsent:Stderr
+
+    "
+     Processor activeProcess stdout
+    "
+    
+    "
+     |out sema|
+     
+     out := WriteStream on:''.
+     sema := Semaphore new.
+     [
+        Processor activeProcess environmentAt:#Stdout put:out.
+        'hello world' printCR.
+        sema signal.
+     ] fork. 
+     sema wait.
+     Transcript showCR:('output was: ''',out contents,'''').
+    "
+!
+
+stdin
+    "the processes stdin.
+     By default, this is Stdin, but it can be overwritten
+     (for example to redirect a thread's input from some other place"
+     
+    ^ self environmentAt:#Stdin ifAbsent:Stdin
+!
+
+stdout
+    "the processes stdout.
+     By default, this is Stdout, but it can be overwritten
+     (for example to redirect a thread's output to some other place"
+     
+    ^ self environmentAt:#Stdout ifAbsent:Stdout
+!
+
 threadVariableValueOf:aKey
     "return the value of a thread local variable, or nil if no such variable exists"
 
@@ -2146,6 +2186,14 @@
     "
 !
 
+transcript
+    "the processes transcript.
+     By default, this is Transcript, but it can be overwritten
+     (for example to redirect a thread's output to some other place"
+     
+    ^ self environmentAt:#Transcript ifAbsent:[self stderr]
+!
+
 withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock
     "evaluate a block with the threadLocalVariable being bound to aValue;
      undo the variable binding afterwards."