How to start an external application from Scala

How to start an external application from Scala?

+3
source share
4 answers

Use the Process library , which was part of SBT but is now separate from it. You can find it here in the Scala Tools repository.

However, it can be simple:

import Process._
"find project -name *.jar" ! log

Edit

As for Scala 2.9.0, this is available in the standard library under scala.sys.process. Instead of importing Process._you should import the scala.sys.process._package object.

+9
source

Scala JVM, , Java, Runtime.getRuntime().exec(...) (, API Java).

java.lang.ProcessBuilder .

+2

This will open the default program file:

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)

+1
source

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

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

Source: https://habr.com/ru/post/1720176/


All Articles