【发布时间】:2012-05-24 08:44:34
【问题描述】:
我想使用 Eclipse IDE 从 java prog 运行 sudo 命令,但它没有运行,不要求输入密码,也没有在控制台中显示任何输出消息,请告诉我 我的编是
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);
}
}
}
【问题讨论】:
-
stackoverflow.com/questions/10732526/… 的重复 您不应两次发布相同的问题,尤其是在同一小时内。如果您被允许访问该站点,该站点将被淹没。给人们一些时间来回复,如果您没有得到任何足够好的回复,请尝试编辑您的问题以使其更清晰