prompt for user input when running scala program with sbt

五迷三道 提交于 2019-12-05 23:25:27

问题


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.


回答1:


Add the following to your build.sbt

connectInput in run := true

From the sbt documentation in Configuring Input



来源:https://stackoverflow.com/questions/28574678/prompt-for-user-input-when-running-scala-program-with-sbt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!