Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issuing native system commands in Scala

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?

like image 643
Tony Avatar asked Jun 17 '10 19:06

Tony


2 Answers

Best way to do that is to use scala.sys.process.

like image 191
Daniel C. Sobral Avatar answered Oct 05 '22 20:10

Daniel C. Sobral


import scala.sys.process._  val vimLocation: String = "whereis vim" !! 

reference

like image 39
Johan Prinsloo Avatar answered Oct 05 '22 18:10

Johan Prinsloo