0

Possible Duplicate:
Shutting down a computer using Java

Hi,

I have a Java program that 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!

0

2 Answers 2

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

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();
    }

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.