Feedforward
Feedforward

Reputation: 4869

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?

Upvotes: 6

Views: 1292

Answers (1)

Artyom Degtyarev
Artyom Degtyarev

Reputation: 2888

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
        }
    }
}

Upvotes: 5

Related Questions