Prompt for user input when running scala using sbt

I have a very simple scala program:

object TakeInputs { def main(args: Array[String]) { val name = readLine("What is your name?") println(name) } } 

When I try to run this using sbt "project myproject" "run-main TakeInput" it does not wait for user input, and the program just ends up What is your name?null as an output.

Is there a way to make sbt wait for user input (for example, what happens if readLine is run in the sbt console)? I can provide inputs as command line parameters, but I have a lot of them, and I would like to make the program more convenient for the user, showing messages that the user should enter next. Thank you

+8
command-line scala sbt user-input
source share
1 answer

Add the following to your build.sbt file:

 connectInput in run := true 

From sbt documentation in Configuring Input

+8
source share

All Articles