Home:ALL Converter>Using JNA or similar to shutdown and restart computer in linux and mac

Using JNA or similar to shutdown and restart computer in linux and mac

Ask Time:2011-10-03T17:53:20         Author:Angeline

Json Formatter

I am trying to write a function in java that will shutdown, force shutdown, restart and force restart the computer and it should work on Windows, Linux and Mac.

Windows is not a problem, but I am unable to run commands to shutdown on Linux due to the sudo privileges. I was therefore thinking of using JNA to shut down the computer (i know you can use JNA to do this on windows), but I can't find any examples online for linux or mac.

Can anyone help me out? It will be much appreciated!

Even if it's not through JNA, it would help me a lot as long as I can find some way to accomplish this.

Author:Angeline,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7633433/using-jna-or-similar-to-shutdown-and-restart-computer-in-linux-and-mac
yy