执行shell进程时设置当前工作目录

The*_*ius 18 scala process

我想sbt update在我的源代码中调用,以更新多个sbt项目.在shell中这很容易:

cd /path/to/project && sbt update
Run Code Online (Sandbox Code Playgroud)

但是,如果我scala.sys.process在我的代码中使用它,它将不记得cd因此sbt在错误的目录中调用.像这样的代码:

import scala.sys.process._
("cd /path/to/project" #&& "sbt update").!!
Run Code Online (Sandbox Code Playgroud)

我没有在文档中找到通过控制台设置sbt的项目路径的任何可能性.如果像这样的东西工作会很好:

"sbt -projectPath /path/to/project update".!!
Run Code Online (Sandbox Code Playgroud)

如果这样的事情是可能的,这将为我节省很多麻烦!(特别是它在UNIX和Windows上运行.)

0__*_*0__ 35

ProcessBuilderProcess对象上使用其中一个工厂方法:

sys.process.Process(Seq("sbt","update"), new java.io.File("/path/to/project")).!!
Run Code Online (Sandbox Code Playgroud)

有关更多文档,请参阅sys.process包scaladoc文件.不幸的是,它没有提到'当前工作目录'参数,但它们在对象的文档中Process.