Reputation: 16825
How to start external application from Scala?
Upvotes: 3
Views: 2361
Reputation: 53896
This will open file with default program :
java.awt.Desktop.getDesktop.open(new java.io.File("<PATH_TO_FILE>"))
Doc : http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html#open(java.io.File)
Upvotes: 1
Reputation: 297305
Use the Process library, which was a part of SBT but is now being separated from it. You can find it here in the Scala Tools repository.
With that, it can be as simple as:
import Process._
"find project -name *.jar" ! log
Edit
As for Scala 2.9.0, this is available on the standard library, under scala.sys.process
. Instead of importing Process._
, you should import scala.sys.process._
, the package object.
Upvotes: 9
Reputation: 207026
Since Scala runs on the JVM, you can do this the same way as you would in Java, by using Runtime.getRuntime().exec(...)
(look that up in the Java API documentation).
You can also use java.lang.ProcessBuilder
for more control.
Upvotes: 2
Reputation: 134340
There is a very good library (DSL) written for this called simple-build-tool
cat(file) #| "grep -i scala" !
Upvotes: 0