954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Shutdown PC running in Ubuntu

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.

gunjannigam
Junior Poster
147 posts since Aug 2009
Reputation Points: 40
Solved Threads: 15
 

Well I got it done by this code

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author gunjan
 */
public class ShutDown {
    public static void main(String[] args)
    {
        try {
            Runtime.getRuntime().exec("shutdown -h 0");
        } catch (IOException ex) {
            Logger.getLogger(ShutDown.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}


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

gunjannigam
Junior Poster
147 posts since Aug 2009
Reputation Points: 40
Solved Threads: 15
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You