Linux(centos 6):
第 1 步
$:yum install xxx
返回一些消息,例如
"Are you OK with your IP being logged? (Y)es/(N)o"
第 2 步
$:Y
安装正在进行。(其他命令可能有步骤 3)
但是我怎样才能用java执行这个命令呢?
这是我的java代码:
String[] commands = new String[]{"yum","install","xxx"};
Runtime run = Runtime.getRuntime();
Process pr = run.exec(commands);
Reader reader = new InputStreamReader(pr.getInputStream());
BufferedReader bf = new BufferedReader(reader);
bf 包括
"Are you OK with your IP being logged?"
现在我如何执行命令(“Y”
)以便安装可以继续
请帮助我。
我不知道如何使用“y”(是)执行命令,但您可以按如下方式运行 yum
yum -y install xxx
-y, --assumeyes Assume yes; assume that the answer to any question which would be asked is yes. Configuration Option: assumeyes See: https://linux.die.net/man/8/yum
我是一名优秀的程序员,十分优秀!