'A simple console while loop that captures the console input and prints to console not working

Why does the below code when run in sbt just print out continuously...

[Info] command:null
[Info] command:null
[Info] command:null
[Info] command:null

I thought readline will block until I enter something in the console.

def main(args: Array[String]): Unit = {
    
    var command = ""
    while (command != "exit") {
      command = scala.io.StdIn.readLine()
      println(s"command: $command")

    }

  }

If I paste this into ammonite it works as expected, it waits for my input that outputs it to the console. Typing "exit" exits the application.



Solution 1:[1]

SBT docs (https://www.scala-sbt.org/1.x/docs/Forking.html) describe the issue of input handling when forking:

By default, the standard input of the sbt process is not forwarded to the forked process. To enable this, configure the connectInput setting:

run / connectInput := true

To disable forking use something like this:

Compile / run / fork := false

or:

fork := false

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 y?s??la