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!

Community
  • 1
  • 1
user726219
  • 413
  • 1
  • 5
  • 5

2 Answers2

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);
}
Andrei Stanca
  • 908
  • 2
  • 11
  • 26
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();
    }

}
edgarmtze
  • 24,683
  • 80
  • 235
  • 386