在某些Windows 7计算机上,当我打电话给“wmic csproduct get'从命令行,我得到了应有的结果。当我从java运行时调用它时,它会抛出一个"提供者加载失败"。截至目前,它似乎只出现在Windows 7机器上,而不是所有Windows 7机器上。下面是一个产生相同结果的示例程序:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TestMain {
private static String console(String string) {
String result = ""; //$NON-NLS-1$
String error = "";
try {
Process p = Runtime.getRuntime().exec(string);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line + '\n';
}
input.close();
input = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = input.readLine()) != null) {
error += line + '\n';
}
input.close();
} catch (Exception e) {
System.err.println("Unknown error occurred with command");//$NON-NLS-1$
e.printStackTrace();
}
System.err.println(error);
return result.trim();
}
public static void main(String[] args) {
System.out.println(TestMain.console("c:/windows/system32/wbem/wmic.exe csproduct get"));
}
}
还有一些事情: