尝试使用 ProcessBuilder 通过 Java 运行 sed 命令时出现 IOException:
ERROR: java.io.IOException: Cannot run program "sed -i 's/hello world//g'
/home/user/test": error=2, No such file or directory
命令是sed -i 's/hello world//g' /home/user/test
但问题不是命令,我可以通过终端运行相同的命令,它会删除字符串“hello world”
public void removeString(String str, String file) throws IOException {
String command = "sed -i \'s/" + str + "//g\' " + file;
System.out.println(command);
ProcessBuilder pb = new ProcessBuilder(command);
Process p = pb.start();
}
是什么导致进程无法找到文件?