943,150 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 712
  • Java RSS
Jan 28th, 2010
0

Shutdown PC running in Ubuntu

Expand Post »
I am using Ubuntu 9.04. I want to shutdown my PC using Java, when some Event is called. Please suggest what could be done.
Similar Threads
Reputation Points: 40
Solved Threads: 15
Junior Poster
gunjannigam is offline Offline
147 posts
since Aug 2009
Jan 28th, 2010
0
Re: Shutdown PC running in Ubuntu
Well I got it done by this code
Java Syntax (Toggle Plain Text)
  1.  
  2. import java.io.IOException;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5.  
  6. /*
  7.  * To change this template, choose Tools | Templates
  8.  * and open the template in the editor.
  9.  */
  10.  
  11. /**
  12.  *
  13.  * @author gunjan
  14.  */
  15. public class ShutDown {
  16. public static void main(String[] args)
  17. {
  18. try {
  19. Runtime.getRuntime().exec("shutdown -h 0");
  20. } catch (IOException ex) {
  21. Logger.getLogger(ShutDown.class.getName()).log(Level.SEVERE, null, ex);
  22. }
  23. }
  24.  
  25. }

But the problem is that I need to run this code as root or superuser. Is there a way to login as root using Java and then run this code
Reputation Points: 40
Solved Threads: 15
Junior Poster
gunjannigam is offline Offline
147 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Connect from java to ms access, sql,oracle
Next Thread in Java Forum Timeline: Explanation of singleton and factory classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC