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

1

6

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?

Coalfish answered 14/7, 2019 at 22:20 Comment(1)
readLine() ==> readLine()!!Colettacolette
S
5

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
        }
    }
}
Shellfish answered 15/7, 2019 at 8:12 Comment(1)
use ticks around 'in' ``` macosX64("macos") { binaries { executable { runTask?.standardInput = System.in } } } ```Bohol

© 2022 - 2024 — McMap. All rights reserved.