Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

readLine() doesn't wait for user input in Kotlin/Native

Here is a simple script

fun main() {
    print("ready> ")
    val input = readLine()
    println("User input: $input")
}

When I run this program with gradle runReleaseExecutableMacos I expect that I'll see a ready> prompt and will have a possibility to type some chars. But this program finishes immediately with User input: null as a result.

Am I missing something?

like image 244
Feedforward Avatar asked Jul 14 '19 22:07

Feedforward


1 Answers

To achieve the behavior you desire, you can run the executable file produced by the Gradle. It will have an extension *.kexe.


Also, you can extend your build.gradle file with additional parameter. you got to add something like this:

macosX64("macos") {
    binaries {
        executable {
            runTask.standardInput = System.in
        }
    }
}
like image 60
Artyom Degtyarev Avatar answered Sep 18 '22 09:09

Artyom Degtyarev