When i use this from NetBeans it's work but when i use outside of NetBenas don't Code of the ShutDown Class is:
import java.io.IOException; public class ShutDown { public static void shutdown() throws RuntimeException, IOException { String shutdownCommand; String operatingSystem = System.getProperty("os.name"); if (operatingSystem.startsWith("Lin") || operatingSystem.startsWith("Mac")) { shutdownCommand = "shutdown -h now"; } else if (operatingSystem.startsWith("Win")) { shutdownCommand = "shutdown.exe -s -t 0"; } else { throw new RuntimeException("Unsupported operating system."); } Runtime.getRuntime().exec(shutdownCommand); System.exit(0); } }
Code of the ShutDown Button is:
private void ShutDownBtnActionPerformed(java.awt.event.ActionEvent evt) { try { ShutDown.shutdown(); } catch (RuntimeException ex) { Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); } }


LinkBack URL
About LinkBacks
Reply With Quote
). Every good IDE takes care about the running process whether it's finishes or still in...waiting. That why your Shutdown class works within your IDE. If you run this class outside your "protected" IDE environment your class is lost. Why? Let analyse your code. The command Runtime.getRuntime().exec(shutdownCommand); is fired then the next command is executed....and it is an EXIT, your JVM terminates and your previous command is probably still in process. Remember Java JVM works asynchronously.