Linux中的WMIC返回[wmi/WMIC.c:212:main()]错误:检索结果数据



我尝试在java中使用wmic来获取设备信息,当我使用带有命令wmic-U user%password//192.168.xxx.xx"从Win32_service中选择名称、状态"|直接grep WinRM,我问过我的同事,他说错误一定是由Cmd字符串数组引起的,因为字符串结果得到了一个值[wmi/wmic.c:212:main((]错误:检索结果数据,但我就是找不到问题所在。

这是我的代码:

String[] Cmd = new String[]{"wmic", "-U", "user%password", "//192.168.xxx.xx", ""select name,status from Win32_service" | grep WinRM"};
try {
for (String s : Cmd) {
System.out.println("Cmmand String:" + s);
}
Process proc = null;
proc = Runtime.getRuntime().exec(linuxCmd);
proc.getOutputStream().close();
InputStreamReader ir = new InputStreamReader(proc.getInputStream(), Charset.forName("x-windows-950")); //Using charset "x-windows-950" For the decode of the Traditional Chinese Windows.!!!                
LineNumberReader input = new LineNumberReader(ir);
String line;
StringBuilder sb = new StringBuilder();
//                System.out.println("Column Name: " + line);
while ((line = input.readLine()) != null) {
//                    logger.debug("Result" + input.getLineNumber() + ":" + line);
sb.append(line.trim()).append("n");
}
String result = sb.toString().trim();
System.out.println("Result: " + result);
} catch (Exception ex) {
}

之所以出现错误,是因为它似乎是grep作为wmi查询的一部分,它在使用where而不是grep后工作。

最新更新