vahid
vahid

Reputation: 1218

Redirect both stdout and stderr to output stream in Scala

What I'd like to do in Scala is redirect both standard output and standard error to output streams. I am aware of scala.Console.withOut and scala.Console.withErr but it seems I need to call these functions separately, which leads to running my command (function) twice:

scala.Console.withOut(out)(f)
scala.Console.withErr(out)(f)

I'd like to call f only once and get both out and err in streams.

Upvotes: 0

Views: 709

Answers (1)

Joe K
Joe K

Reputation: 18424

You can nest them:

Console.withOut(out) {
  Console.withErr(out) {
    f
  }
}

Upvotes: 2

Related Questions