Scala 在不同的工作目录上运行进程

Wlo*_*ast 6 scala process ioexception

我无法使用 Process("dir/e.exe") 因为 e 需要在它自己的目录上执行,否则它无法访问其资源。但每当我尝试更改工作目录时,我都会收到异常:

Process("e.exe", new File(dir)) 
Process("e.exe", new File("\"+ dir))
Process("e.exe", new File(new File(dir).getCanonicalPath()))  

Caused by: java.io.IOException: Cannot run program "e.exe" (in directory ".
\dir"): CreateProcess error=2, The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)

这些不起作用,它们给了我完全相同的错误。还有其他选择吗?

编辑:这就是我的目录的样子:

MyFolder:
|-app.jar
|-folderWithExe
  \-e.exe
Run Code Online (Sandbox Code Playgroud)

som*_*ytt 2

尝试“./e.exe”或输入“.” 在路上。

(为了清晰起见进行了编辑。)

事后分析:问题是,如果没有 SO,你能做什么来快速解决这个问题?您确实想要一条消息说:“尝试这些位置后找不到要运行的程序...”或者甚至可能在类似“当前目录中-Dprocess.debug有一个名为的文件,foo但我无法运行它”之类的消息因为...”

作为记录:

import sys.process._
import java.io.File

//System setSecurityManager new SecurityManager
Console println Process("./tester", new File("subdir")).lines.toList
Run Code Online (Sandbox Code Playgroud)

显示该路径很重要:

apm@mara:~/tmp/cdtest$ echo $PATH
/home/apm/go1.1/go/bin:/home/apm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
apm@mara:~/tmp/cdtest$ vi runit.scala
apm@mara:~/tmp/cdtest$ scalam runit.scala
java.io.IOException: Cannot run program "tester" (in directory "subdir"): error=2, No such file or directory
apm@mara:~/tmp/cdtest$ grep tester runit.scala 
Console println Process("tester", new File("subdir")).lines.toList
apm@mara:~/tmp/cdtest$ PATH=$PATH:.
apm@mara:~/tmp/cdtest$ scalam runit.scala
List(file1, file2, tester)
Run Code Online (Sandbox Code Playgroud)