处理将在 Linux Web 服务器上运行的应用程序以从某个目录中删除日志,但是我不断收到 FileNotFound 异常。
这是代码:
public static void deleteLOG() {
try {
ProcessBuilder probuilder = new ProcessBuilder("find /home/root/multicraft/servers/ -name '*.log' -delete");
probuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
和例外
java.io.IOException: Cannot run program "find . -name '*CoreData*' -delete" (in directory "/home/root/multicraft/servers"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(Unknown Source)
at com.mcprohosting.com.nodecleanup.Preprocess.deleteCoreData(Preprocess.java:23)
at com.mcprohosting.com.nodecleanup.handlers.CleanupHandler.executeCleanup(CleanupHandler.java:36)
at com.mcprohosting.com.main.NodeCleaner.init(NodeCleaner.java:29)
at com.mcprohosting.com.main.NodeCleaner.main(NodeCleaner.java:25)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
但是命令 cd /home/root/multicraft/servers 工作得很好。
我也试过:
ProcessBuilder probuilder = new ProcessBuilder("find . -name '*Backup*' -delete");
probuilder.directory(new File("/home/root/multicraft/servers/"));
probuilder.start();