怎样实现用Java执行cmd命令,然后获取cmd的输出
File file=new File(strName+".java");FileOutputStream fos=new FileOutputStream(file);
OutputStreamWriter osr=new OutputStreamWriter(fos);
BufferedWriter bw=new BufferedWriter(osr);
bw.write(text.getText());
bw.close();
String cmd = "javac ";
String param =file.getName();
Process child = Runtime.getRuntime().exec(cmd+param); //没有输出
//Process child = Runtime.getRuntime().exec( "ipconfig /all "); //输出正常
try{ Thread.sleep(1000);}
catch(Exception ex){ex.printStackTrace();}
InputStream is = child.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
String str="";
while ((str=br.readLine())!=null)
{
editInformation=editInformation+str+"\r\n";
}
System.out.println(editInformation);
br.close();
Process child = Runtime.getRuntime().exec(cmd+param); //没有输出
//Process child = Runtime.getRuntime().exec( "ipconfig /all "); //输出正常
为什么啊? 怎样才能正常输出?