-6

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

Is this possible?

2 Answers2

2

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!

Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
0

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");
Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107