Problem with Kotlin readLine() function using IntelliJ internal console

Viewed 628

When I try to read some value from a user, I get strange behavior.

For example, if I have one simple program:

fun main() {
    print("insert value: ")
    val tmp = readLine()
    println("value = $tmp")
}

I would expect the next behavior of the program:

insert value: 1
value = 1

But I get the next behavior:

insert value: 1
1
value = 1

So I would expect to insert the value 1, hit Enter, and the program would output value = 1. But instead of this, I have to input the value 1, hit Enter, input the value 1, hit Enter, and then I get the desired output.

Is there any option to run the Kotlin program in an external console instead of the IntelliJ internal console? Because I updated IntelliJ to the latest version and assume that maybe there is a problem with the new version?

1 Answers

on your Kotlin REPL

   fun main() {
        print("insert value: ")
        val tmp = readLine()
        println("value = $tmp")
    }
    main()

Then to execute you press Ctrl+Enter

You get:

insert value: 

then insert the value 1 and press Ctrl+Enter one more time to execute.

and the output is:

insert value: 1
value = 1
Related