package com.haxademic.demo.system;

import java.io.IOException;

import com.haxademic.core.app.P;
import com.haxademic.core.app.PAppletHax;

public class Demo_WindowsComputerRestart
extends PAppletHax {
	public static void main(String args[]) { PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }

	public void setup() {
		super.setup();		
	}

	public void drawApp() {
		p.background(0);
		p.text(p.frameCount, 20, 30);
		if(p.frameCount == 90) {
			// "cmd.exe /C";
			String command = "SHUTDOWN -r -t 10";
	        Process p;
			try {
				p = new ProcessBuilder(command)
				        .redirectErrorStream(true)
				        .redirectOutput(ProcessBuilder.Redirect.INHERIT)
				        .start();
				P.out("Exit value: " + p.exitValue());
			} catch (IOException e) {
				e.printStackTrace();
				P.out("Script failed");
			}

		}
	}
}

@@ -33,70 +33,8 @@
 m;%0A%0A
-import java.io.IOException;%0A%0Aimport com.haxademic.core.app.P;%0A
 impo
@@ -71,16 +71,16 @@
 letHax;%0A
+
 %0Apublic 
@@ -258,54 +258,8 @@
  %7D%0A%0A
-%09public void setup() %7B%0A%09%09super.setup();%09%09%0A%09%7D%0A%0A
 %09pub
@@ -364,295 +364,206 @@
 %0A%09%09%09
-// %22cmd.exe /C%22;%0A%09%09%09String command = %22SHUTDOWN -r -t 10%22;%0A%09        Process p;%0A%09%09%09try %7B%0A%09%09%09%09p = new ProcessBuilder(command)
+try %7B %0A%09%09%09%09// /K : runs command specified by following string %0A%09%09%09%09// -r = restart%0A%09%09%09%09// -t 10 = wait 10 seconds
 %0A%09%09%09%09
-        .redirectErrorStream(true)%0A%09%09%09%09        .redirectOutput(ProcessBuilder.Redirect.INHERIT)%0A%09%09%09%09        .start();%0A%09%09%09%09P.out(%22Exit value: %22 + p.exitValue());
+Runtime.getRuntime().exec(new String%5B%5D %7B%22cmd%22, %22/K%22, %22SHUTDOWN -r -t 10%22%7D);%0A%09%09%09%09
 %0A%09%09%09
@@ -575,10 +575,8 @@
 ch (
-IO
 Exce
@@ -589,67 +589,84 @@
 e) %7B
+ 
 %0A%09%09%09%09
-e.printStackTrace(
+System.out.println(%22Didn't work!%22
 );
+ 
 %0A%09%09%09%09
-P.out(%22Script failed%22
+e.printStackTrace(
 );
+ 
 %0A%09%09%09%7D
-%0A
+ %09%09
 %0A%09%09%7D

Update Demo_WindowsComputerRestart.java