Take the 2-minute tour ×

I found some strange behavior when Console.withOut used within an actor. For code:

case object I
val out = new PipedOutputStream
val pipe = new PipedInputStream(out)
def read: String = ** read from `pipe` stream
class A extends Actor{
  var b: Actor = _
    b = actor { loop { self react {
          case I => println("II")
  def act = {
    loop { self react {
        case I =>
          b ! I
  val a = new A
  a ! I
  Thread sleep 100
  println("!!\n" + read + "!!")

got following output:


Any idea why output from A actor's act method is also redirected? Thank you for your answers.

UPDATE: Here is read function:

  def read(instream: InputStream, acc: List[Char] = Nil): String =
    if(instream.available > 0) read(instream, acc :+ instream.read.toChar) else acc mkString ""
  def read: String = read(pipe)
share|improve this question
Could you also post the code with which you read from the pipe? –  axel22 Feb 15 '11 at 9:00
add comment

1 Answer

It seems to me, on the contrary, that neither actor has its output redirected, since withOut will have finished executing long before println("II") is called. Since this is all based on DynamicVariable, however, I'm not willing to bet on it. :-) The absence of working code precludes any testing as well.

share|improve this answer
Agreed. Neither should be visible. My thinking is that the code for the read does something it's not supposed to, hence the printing. –  axel22 Feb 15 '11 at 12:14
Agreed. withOut is only active while b is created, not while it is responding to its message. Consistent with this, the !!'s appear there also (presumably unredirected). So either read calls setOut or nothing is redirected. –  Rex Kerr Feb 15 '11 at 12:31
read doesn't call setOut, but all outputs after outer actor is started is redirected for a reason i cannot see. –  fehu Feb 15 '11 at 17:33
add comment

Your Answer


