在java程序中的powercfg没有错误没有输出,当我运行它时没有显示任何输出
import java.net.*;
import java.io.*;
public class ip{
public static void main(String args[]) throws IOException{
try{
String inputLine;
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd.exe /c powercfg/batteryreport");
BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
//pingResult += inputLine;
}
}
catch(Exception e){
System.out.println(e);
}
}
}发布于 2014-10-30 18:06:50
这是因为至少在Windows7上,如果你试图从命令运行powercfg/batteryreport,你将得到“无效参数--如果你不在笔记本电脑上,试着使用"/?”获取帮助“。要查看来自Java的这条消息,您应该附加p.getErrorStream()
例如,尝试使用'powercfg energy‘
https://stackoverflow.com/questions/26649479
复制相似问题