In Windows, it is possible to shutdown a machine through a java program by natively(JNA) calling a ExitWindowsEx function in Windows API. I am looking for something similar in linux. I know this can be done by executing commands but then I cannot rely on parsing the human-readable text.
Is IPC(DBus) the only way to do this or is it possible to load some library natively and the call the shutdown method natively. If there is a simpler way to do it please do let me know.
Using JNA or similar to shutdown and restart computer in linux and mac
I looked at this question earlier but it does not provide an answer as to how to do it programmatically.
Velkan :
Can't your program just invoke sh and execute shutdown command? Like that (needs root):\n\nsystem(\"shutdown\");\n\n\nOr if it's a desktop session:\n\nsystem(\"dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 \"org.freedesktop.login1.Manager.PowerOff\" boolean:true\");\n\n\nOr you can instead include a DBus connector library and do a proper IPC call.",
2016-11-03T07:03:15