Results 1 to 2 of 2

Thread: Java Runtime.exec() in sudo mode

  1. #1
    Join Date
    Oct 2008

    Java Runtime.exec() in sudo mode

    I want to run command line program such as,
    # ifconfig eth0 up/down
    # route add default gw

    from a Java program using the Runtime.exec() command. But when I run the program, no message is showing and silently discarded and have no impact on the system.
    Plz tell me, how is can be done.
    From other commands, such as, ifconfig, route, I can capture the output.

    And how can a program be run in privileged mode without any user interaction?

    Thanks in advance.


  2. #2
    Join Date
    May 2009

    Re: Java Runtime.exec() in sudo mode

    gksudo works but still asks for a password during runtime (in GUI mode):

    public static void main(String[] args) {
        try {
            Runtime r = Runtime.getRuntime();
            r.exec("gksudo gedit /etc/X11/xorg.conf");
        } catch( Exception exc ) {
    If you google I'm pretty sure you'll find how to specify the password silently if you don't want the user to be asked for it.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts