我正在使用expectit 0.9.0
和java version 1.8.0_201
,expect.sendLine()
可以完美地使用单字命令,但是当涉及到多字命令时,它表现得很奇怪,有时会删除空格并有时会从命令字符串中删除任何单个字符。
输入的命令:esxcli network ip interface ipv4 get
行为:`
esxcli network ip terface ipv4 get
esxcli network ipinterface ipv4 get
此行为不一致,有时会完美运行。 下面是我的代码-
try {
String username="root";
String password="root_password";
Process process = Runtime.getRuntime()
.exec("ipmitool -I lanplus -H <myipaddress> -U <admin_username> -P <admin_pasword> sol activate");
Expect expect = new ExpectBuilder()
.withInputs(process.getInputStream())
.withOutput(process.getOutputStream())
.withTimeout(50, TimeUnit.SECONDS)
.withExceptionOnFailure()
.build();
try {
expect.sendLine();
expect.sendLine("esxcli network ip interface ipv4 get");
expect.sendLine("ENDCOMMAND");
System.out.println(expect.expect(contains("ENDCOMMAND")).getBefore());
}catch (Exception e) {
e.printStackTrace();
}
请帮助我。谢谢。