Problems with ProcessBuilder at linux
807605Sep 27 2007 — edited Sep 28 2007Hello together,
I want use the linux command su (/bin/su) in a java program and receive the root shell if the password was right.
Therefore I tried the followoing approach:
import java.io.*;
import java.util.*;
public class sutest {
public static void main(String[] args) {
try{
ProcessBuilder builder = new ProcessBuilder();
builder.command( "bash", "-c", "su" );
builder.directory( new File("/") );
Process p = builder.start();
PrintStream printer = new PrintStream(p.getOutputStream());
String str="my password";
printer.println(str);
printer.flush();
Scanner s = new Scanner( p.getInputStream() ).useDelimiter( "\\Z" );
if (!s.hasNext()) {
Scanner sa = new Scanner(p.getErrorStream());
while (sa.hasNext()) {
System.out.println(sa.nextLine());
}
}
while (s.hasNext()) {
System.out.println( s.next() );
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
But the only thing I get is the following message:
su: must be run from a terminal
<img class="emoticon" src="images/emoticons/confused.gif" border="0" alt="" />
Are there any possibilities use su in my java application and how it is possible to set for su a terminal environment in java?
greetz itachy
p.s. sorry for my bad english<img class="emoticon" src="images/emoticons/happy.gif" border="0" alt="" />