wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes some ideas about control pc? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "some ideas about control pc?" Watch "some ideas about control pc?" New topic
Author

some ideas about control pc?

li yuanchun
Greenhorn

Joined: Apr 21, 2009
Posts: 3
hi ,everybody , i wanner write some codes in order to control pc , such as shutdown pc ,reboot pc . i don't like the way follow codes:
Runtime run = Runtime.getRuntime();
run.exec("sudo shutdown -h now")


have you any ideas?

whole thanks´╝ü
Manoj Maniraj
Ranch Hand

Joined: Mar 25, 2009
Posts: 38
I dont think there is another way to achieve this... anybody?


http://manojmaniraj.blogspot.com
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

You could write a JNI class that invokes the OS-level functions directly.

Although rebooting an OS from inside any application is a questionable practice. I'd generally put the application in a shell script and have it set an exit code that would then determine what, if any reboot-style action would be done by the next step in the shell script. That way I'd have an app that shutdown clean, and wouldn't have to worry about it maybe going crazy and rebooting unexpectedly due to a bug.


Customer surveys are for companies who didn't pay proper attention to begin with.
li yuanchun
Greenhorn

Joined: Apr 21, 2009
Posts: 3
i think that isn't safety , it can achieve that with shell only.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

A shellscript is an application, the shell by itself is an application, and the shutdown-applet provided by the desktop/the menu is an application too. I don't see much difference.


http://home.arcor.de/hirnstrom/bewerbung
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

The difference is that the shell script is a text file. To monitor its behavior, you can simply list it. System-controlling shell scripts tend to be fairly simple and straightforward.

Applications, on the other hand, are binary "black boxes", and if the application's primary purpose is something other than simple system control, there's always a chance that there may be unforseen logic paths that can cause the system to shut down unexpectedly.

This isn't to say that shell scripts are absolutely safer, but they are more transparent.

The real reason why I'd prefer the shutdown to be done outside the app, however, is that that way the app will have been terminated (hopefully cleanly) before the shutdown process begins. So you won't have the danger of OS yanking resources out from under you while the app still has threads executing, buffers unflushed, network connections open, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: some ideas about control pc?