2014-10-30 76 views
0

POWERCFG在Java程序中沒有錯誤沒有輸出,當我運行它不會顯示任何輸出POWERCFG在Java程序中沒有錯誤沒有輸出

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); 
} 
} 
} 
+0

是'inputLine'爲空。你檢查過了嗎? – 2014-10-30 09:51:11

回答

0

這是因爲至少在Windows 7中,如果您嘗試運行powercfg/batteryreport from cmd,你會得到 「無效的參數 - 嘗試」/?「尋求幫助」,如果你不在筆記本電腦上。要看到從Java此消息應該高度p.getErrorStream()

嘗試「POWERCFG - 能量」,例如

+0

即時通訊使用Windows 8,其不工作相同沒有輸出 – 2014-10-30 10:12:51

+0

再次,你在筆記本電腦上?您是否嘗試在Java程序或附加的errorStream之外的cmd中使用powercfg? – igorepst 2014-10-30 10:14:41

+0

在CMD它的工作,但在Java它沒有工作 – 2014-10-30 12:30:05