public static void main(String[] args) {
Process p = null;
try {
//p = Runtime.getRuntime().exec("notepad");//-------------0
//p = Runtime.getRuntime().exec("shutdown -s -t 3600");//-------------1
Thread.sleep(5000);
//p = Runtime.getRuntime().exec("shutdown -a");//------------2
} catch (Exception e) {
e.printStackTrace();
}
p.destroy();
}
执行0:
用exec运行notepad,5秒后notepad结束,java程序结束。一切正常
(执行1)或(执行1和2):
用exec运行shutdown -s -t 3600,5秒后java程序结束,shutdown不能结束请问高手何故?怎样用Java结束shutdown进程?
Process p = null;
try {
//p = Runtime.getRuntime().exec("notepad");//-------------0
//p = Runtime.getRuntime().exec("shutdown -s -t 3600");//-------------1
Thread.sleep(5000);
//p = Runtime.getRuntime().exec("shutdown -a");//------------2
} catch (Exception e) {
e.printStackTrace();
}
p.destroy();
}
执行0:
用exec运行notepad,5秒后notepad结束,java程序结束。一切正常
(执行1)或(执行1和2):
用exec运行shutdown -s -t 3600,5秒后java程序结束,shutdown不能结束请问高手何故?怎样用Java结束shutdown进程?
shutdown -s -t 3600
能够保证关机吗?
在cmd下运行shutdown -s -t 3600能够保证关机,运行shutdown -a就能结束shutdown进程
Process p = null;
try {
//p = Runtime.getRuntime().exec("notepad");//-------------0
//p = Runtime.getRuntime().exec("shutdown -s -t 3600");//-------------1
Thread.sleep(5000);
//p = Runtime.getRuntime().exec("shutdown -a");//------------2
} catch (Exception e) {
e.printStackTrace();
}
p.destroy();
}
没必要像这么麻烦~!
Thread.sleep(100);
在该行将进程sleep一下就正常了.具体没看exec的源码,原因还未知。