linux - How to execute bash command with sudo privileges in Java? -


i'm using processbuilder execute bash commands:

import java.io.ioexception;  public class main {     public static void main(string[] args) {         try {             process pb = new processbuilder("gedit").start();         } catch (ioexception e) {             e.printstacktrace();         }     } } 

but want make this:

process pb = new processbuilder("sudo", "gedit").start(); 

how pass superuser password bash?

("gksudo", "gedit") not trick, because deleted since ubuntu 13.04 , need available default commands.

edit

gksudo came ubuntu 13.04 last update.

i think can use this, i'm bit hesitant post it. i'll say:

use @ own risk, not recommended, don't sue me, etc...

public static void main(string[] args) throws ioexception {      string[] cmd = {"/bin/bash","-c","echo password| sudo -s ls"};     process pb = runtime.getruntime().exec(cmd);      string line;     bufferedreader input = new bufferedreader(new inputstreamreader(pb.getinputstream()));     while ((line = input.readline()) != null) {         system.out.println(line);     }     input.close(); }