how do i shut down my OS with java
+2
A:
You cannot directly shut OS with Java, but you can execute a shell script or native program e.g Runtime.getRuntime().exec("shutdown"). Or you can write JNI hook into native system
DroidIn.net
2009-10-20 04:42:20
+5
A:
I believe that since Java is OS independent there is no direct way to do it, other than invoking something from the underlying OS.
Carlos Muñoz
2009-10-20 04:43:01
Java could provide an OS independent method for shutting down the machine.
Tom Hawtin - tackline
2009-10-20 05:12:29
But it doesn't. Which is good :)
Thorbjørn Ravn Andersen
2009-10-20 11:47:28
A:
This page some useful information.... it does not have a direct answer but it will help you.
Shoban
2009-10-20 04:43:33
+3
A:
from : a blog
package com.deepak.entertainment;
import java.io.IOException;
import java.io.OutputStream;
public class Deepak {
public static void main(String[] args) throws InterruptedException {
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(”C:\\WINDOWS\\system32\\cmd.exe”);
OutputStream os = process.getOutputStream();
os.write(”shutdown -s -f -t 90 \n\r”.getBytes());
os.close();
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Ric Tokyo
2009-10-20 04:44:07
Yes, just read the code and you can update what goes in the runtime.exec so that it can be a Linux command or any other OS command.. Linux "shutdown -h now" or "init 0" ..
Ric Tokyo
2009-10-20 06:46:44
+1
A:
// May need to change for a Swing or SWT application.
System.out.println ("Please shut down your OS now. I'll wait...");
boolean forever = true;
while (forever) {}
:-)
paxdiablo
2009-10-20 05:16:21