We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Shutting down computer
Page Index Toggle Pages: 1
Shutting down computer? (Read 944 times)
Shutting down computer?
Mar 4th, 2009, 3:25pm
 
Hello
I've been searching for a while for this, but no success so far.
Thing is, I need to shut down my computer from processing (being triggered by something else, and not a fixed time)  either by running an external script ( .bat or similar) or directly from processing. ( any other approaches are welcome too)

Anyone has had any success doing so? i'm using windows btw

Many thanks, i hope this hasn't been posted before, but I couldn't find anything regarding this!

(I hope this is the correct place to post this too!)

have a nice day.
Re: Shutting down computer?
Reply #1 - Mar 4th, 2009, 4:39pm
 
got it.
java documentation had the answer
in case anyone wonders the same...  this might help

 try {
   String command = "shutdown -s";
   Process child = Runtime.getRuntime().exec(command);
 } catch (IOException e) {
 }

you can change the arguments to execute different actions (ie: restart, shut down another computer, etc, heres a link with the possible arguments http://www.computerhope.com/shutdown.htm )
there are many other commands that can be executed
http://www.computerhope.com/jargon/e/extecomm.htm
and probably running applications or files( like other sketches)

hope it helps someone

cheers
Re: Shutting down computer?
Reply #2 - Mar 4th, 2009, 4:59pm
 
i use this on Vista:
-shutdown windows
-force running apps to quit
with -t seconds delay

Quote:
void setup() {
  killBill();
}

void killBill() {
  try {
    Runtime.getRuntime().exec("shutdown.exe -s -f -t 0");
  } 
  catch (IOException e) {
    e.printStackTrace();
  }
}



Edit: you answered your own question!
Page Index Toggle Pages: 1