我想使用 Eclipse IDE 从 java prog 运行 sudo 命令,但它没有运行,也没有要求输入密码,也没有在控制台中显示任何输出消息,请告诉我我的 prog 是
public class JavaCommand {
public static void main(String args[]) throws IOException, InterruptedException {
String command="sudo cat /etc/sudoers";
Process myProcess =null;
try {
Runtime runtime=Runtime.getRuntime();
File file=new File("/home/users/admin/temp");
myProcess = runtime.exec(command,null,file);
myProcess.waitFor();
InputStreamReader myIStreamReader = new InputStreamReader(myProcess.getInputStream());
BufferedReader br=new BufferedReader(myIStreamReader);
String line;
while((line=br.readLine())!=null){
System.out.println(line);
}
} catch (IOException anIOException) {
System.out.println(anIOException);
}
}
}