Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prompt for user input when running scala program with 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 with sbt "project myproject" "run-main TakeInput" it doesn't wait for user input and the program just finishes with What is your name?null as the output.

Is there a way to make sbt wait for user input (like what happens if "readLine" is run in sbt console)? I can provide the inputs as command line parameters but I have a lot of them and I would like to make the program more user-friendly by displaying messages indicating what the user should enter next. Thanks.

like image 616
Xiang Avatar asked Feb 18 '15 01:02

Xiang


1 Answers

Add the following to your build.sbt

connectInput in run := true

From the sbt documentation in Configuring Input

like image 116
Justin Pihony Avatar answered Oct 09 '22 04:10

Justin Pihony