开发者

Java - shutdown computer after program run [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Shutting down a computer using Java

Hi,

I have a Java program th开发者_开发技巧at will run 20 times and take around 3 hours to do so. After this, I want my computer to shutdown, or for me to be logged off as a user. Can I do this directly from my program, i.e. directly after the for loop.

for(int i=0; i<20; i++){
//APPLICATION CODE
}

//SHUTDOWN OR LOGGOF CODE

How do I do this?

Thanks!


As an example you could run a system command like this:

public static void main(String arg[]) throws IOException{
        Runtime runtime = Runtime.getRuntime();
        Process proc = runtime.exec("shutdown -s -t 0");
        System.exit(0);
}


public void shutDown() {
    try {
        Runtime
            .getRuntime()
            .exec(
                           "shutdown -s -t 120 -c \"Message telling shutdown has initiliazed. To stop the shutdown.\"");
    } catch (final IOException e) {
        e.printStackTrace();
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜