我正在尝试在 linux 中执行:
command[0] = "~/test/bin/runScript_sh";
Runtime.getRuntime().exec(command);
但是得到一个异常
java.io.IOException: 无法运行程序
error=2, 没有那个文件或目录
可能是因为它无法计算代字号。
可以做什么?
最佳答案
我会自己更换它。
if(path.s.substring(0,1).contains("~"))
path = path.replaceFirst("~",System.getProperty("user.home"));
这会为您提供所需的字符串。
关于java - 在路径中使用波浪号执行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15273524/