开发者

How to start external application from Scala

How t开发者_开发问答o start external application from Scala?


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.


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.


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)


There is a very good library (DSL) written for this called simple-build-tool

cat(file)  #| "grep -i scala" !
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜