Processing - Shutdown a computer

537 views Asked by At

I am working on a "Russian roulette" game in Processing, where one of the buttons shuts down the computer.

Is this possible?

2

There are 2 answers

0
Francisco Romero On

You can use, in Linux:

Runtime.getRuntime().exec("shutdown -h now");

and in Windows:

Runtime.getRuntime().exec("shutdown.exe -s -t 0");

Finally put this sentence to terminate the process:

System.exit(0);

I expect it helps to you!

0
Kevin Workman On

Your question is very broad, but the short answer is yes, this is possible.

However, it's also going to be OS specific: shutting down a Windows computer is different from shutting down a Mac computer, etc.

You can start by googling "java shutdown computer" for a ton of results, but a very basic attempt (taken from this SO question) is something like this:

Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("shutdown -s -t 0");