我想要实现的是从我
创建的 java 应用程序安装软件。我得到了 gksudo 的许可。然后,我输入了我的通行证,程序开始工作,直到出现是/否选项。我怎样才能通过这个问题?
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class TestApp {
public static void main(String[] args) {
Process ls = null;
BufferedReader input = null;
String line = null;
try {
ls = Runtime.getRuntime().exec(
new String[] { "gksudo", "apt-get", "install", "PACKAGE" });
try {
ls.wait(6000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ls = Runtime.getRuntime().exec(new String[] { "y" });
input = new BufferedReader(new InputStreamReader(
ls.getInputStream()));
} catch (IOException e1) {
e1.printStackTrace();
System.exit(1);
}
try {
while ((line = input.readLine()) != null) {
System.out.println(line);
}
ls.destroy();
} catch (IOException e1) {
e1.printStackTrace();
System.exit(0);
}
}
}