Expected sendLine函数正在从命令字符串中删除空格和字符

时间:2020-10-16 22:38:43

标签: java expect pexpect expectit

我正在使用expectit 0.9.0java version 1.8.0_201expect.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();
            }

请帮助我。谢谢。

0 个答案:

没有答案