package cn.silence.demo;import java.io.IOException;/*** @author silence* createTime 2021-12-21-21:46* shutdown 关机 shutdown /? 查看帮助* -s 关机(shutdown缩写)* -r 重启(restart的缩写)* -l 注销(logout)* -t 多长时间以后执行(单位:秒)* -f 强制关闭正在运行的应用程序而不事先警告用户。如果为 /t 参数指定大于 0 的值,则默示为 /f 参数。* shutdown -s -t 3600 意思是在3600秒后关机* shutdown -s -t 00 意思是立马关机* at 12:00 shutdown -s 意思是在12:00的时候关机* 60分钟后关机。如果你中途又不想关机的话可以输入命令 shutdown -a 来取消关机*/
public class Demo1 {public static void main(String[] args) throws IOException, InterruptedException {shutDown();
// Thread.sleep(3000);
// cancelShutDown();}/*** 取消关机*/private static void cancelShutDown() throws IOException {Runtime.getRuntime().exec("shutdown -a");}/*** 关机*/private static void shutDown() throws IOException {Runtime.getRuntime().exec("shutdown -s -t 0 -f");}
}