5

Is there a way to log the output of the Scala REPL in a file ?

John Threepwood
  • 15,593
  • 27
  • 93
  • 149
  • Did you have a look at .scala_history? http://stackoverflow.com/questions/11561719/is-there-a-quick-way-to-show-the-code-of-a-method-declared-in-the-scala-console – Malte Schwerhoff Aug 08 '12 at 20:03
  • @mhs Thank you, but .scala_history only saves the commands I typed, not the REPL output as a whole. – John Threepwood Aug 08 '12 at 20:07
  • My bad, I missed that part of your question. – Malte Schwerhoff Aug 08 '12 at 20:09
  • how about just hitting "save" in your terminal window? – dhg Aug 08 '12 at 20:15
  • According to http://stackoverflow.com/questions/9494014/scala-interactive-interpreter-repl-how-to-redirect-the-output-to-a-text-file it is not possible with 2.9. Give it a try in 2.10. – Malte Schwerhoff Aug 08 '12 at 20:17
  • If your are using Unix-like system (including MacOS), I think `scala | tee log` is the simplest method. It will catch all input and output of your scala REPL to the file named `log`. – Brian Hsu Aug 08 '12 at 23:41

1 Answers1

2

You could import java.util.PrintWriter and have some code like this:

val out = new PrintWriter("out.txt")
out.println("output string")
out.flush();
out.close();
ferk86
  • 2,325
  • 1
  • 23
  • 27