Alex Rivera | Logout

Executing shell commands from Scala REPL

Asked 2012-03-27T08:48:42.260
16

An interesting feature of Scala REPL is if you drop any jar in your %SCALA_HOME%\lib directory, it is available for import from the REPL. I have several jars there, and I often need to find out which ones are available to be included. So I always have to open another command window and find out which jars exist in that directory. It would be great if the REPL allowed me to execute system commands such as dir or ls or at least list all the jars in the above lib directory. What is the easiest way (if any) to invoke shell commands in REPL ?

Edit
Report

1 Answer

18

Alternative: use Scala's sys.process library:

scala> import sys.process._
import sys.process._

scala> "ls /home/dcs/scala-2.9.1.final".!
bin
doc
lib
man
meta
misc
src
res1: Int = 0
answered 2012-03-27T18:25:06.663

Your Answer