Search code examples
intellij-ideakotlin

How to get output of Kotlin IntelliJ scratch file?


A script as simple as

println("a")

doesn't produce any output in the Scratch output window. I expect an a to appear in the output window.

I'm using IntelliJ 2019.1.2 CE.


Solution

  • EDIT: Information regarding the expected functionality

    According to a question I had asked: IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off

    It seems to be the case that the REPL wants to output per line, and will only overflow into the bottom area after a certain line length is reached.

    In the question I state that I generally add some initial padding so that it always flows into the lower area with something similar to: repeat(10) { println("BLANK ") }

    END EDIT

    You have to make sure that Interactive Mode is turned off at the top of the scratch window

    enter image description here

    This will cause prints to be put into the Scratch Output window.

    Be warned, atleast in the version I have of IntelliJ ultimate 2019.1.3, the first 5-9 lines generally dont print so I do something like:

    repeat(9) { println("blank") }