Last Updated: February 25, 2016
·
1.894K
· amirtcheva

Passing command line arguments in Scala REPL

First, create the array of command line arguments:

scala> val args = Array("1")
args: Array[String] = Array(1)

Then call your main function (which just prints out all the arguments):

scala> MyFunc.main(args)
1

If you need to add more arguments, you can just initialize with a larger array, or add more to the existing argument array:

scala> args :+ "2"
res2: Array[String] = Array(1, 2)

scala> MyFunc.main(args)
1
2