问题描述
我尝试在Java中使用wmic来获取设备信息,当我将CLI与命令wmic -U user%password一起使用CLI时,它会成功运行//192.168.xxx.xx“从Win32_service中选择名称,状态” |直接使用grep WinRM, 我问过我的同事,他说错误一定是由Cmd String数组引起的,因为String结果得到一个值[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) {
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)