views:

117

answers:

4

I want to issue a native system command from a Scala program, and perhaps trap the output. ("ls" comes to mind. There may be other ways to get directory information without issuing the command, but that's beside the point of my question.) It would correspond to os.system(...) in Python.

I've looked in "Programming in Scala". I've looked in O'Reilly's "Programming Scala". I've Googled several combinations of terms. No luck yet. Can someone out there give me an example, or point me at a resource where I can find an example?

+1  A: 

Scala is not different from Java in this area, since you can call any Java API functions using Scala's interop features. See for example, java.lang.ProcessBuilder.

Greg Hewgill
A: 

Scala has complete interoperability with Java. So you can call the system commands from Scala as you would from Java. See this to see how to call system commands from Java.

abhin4v
+7  A: 

Best way to do that is use the Process library.

Daniel
+1  A: 

import sbt.Process._

val vimLocation: String = "whereis vim" !!

ref

Johan Prinsloo