无法从Java在Ubuntu上运行重启

时间:2017-11-08 22:31:25

标签: java cron

我无法通过cronjob在Ubuntu PC上从Java运行reboot命令,但直接从终端调用它时可以正常工作。

有人知道问题是什么吗?

这是我的代码:

private static void reboot() throws IOException {
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("reboot");
        System.exit(0);
}

这是用cron执行时的错误:

Exception in thread "main" java.io.IOException: Cannot run program "reboot": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at java.lang.Runtime.exec(Runtime.java:620)
    at java.lang.Runtime.exec(Runtime.java:450)
    at java.lang.Runtime.exec(Runtime.java:347)
    at xyz.stankovic.nikola.minermaintenanceagent.App.reboot(App.java:40)
    at xyz.stankovic.nikola.minermaintenanceagent.App.main(App.java:32)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 5 more

0 个答案:

没有答案