java调用外部控制台出现的小问题?至今没想明白
2010-07-26 23:34
369 查看
public static void main(String[] args0) {
try{
Process process = Runtime.getRuntime().exec ("ipconfig");
InputStreamReader ir=new InputStreamReader(process.getInputStream());
BufferedReader input = new BufferedReader (ir);
String line;
StringBuffer str = new StringBuffer();
int exitVal = process.waitFor();
while ((line = input.readLine()) != null) {
String temp =line;
str.append(temp+"/r/n");
System.out.println(line);
//System.out.println(input.readLine());
}
System.out.println(exitVal);
System.out.println(str.toString());
}catch(Exception e){
System.err.println ("IOException " + e.getMessage());
}
}
为什么直接输出input.readline(),控制台输出的都是空呢?是传说中的缓冲区问题?赋值一下就可以了呢?
try{
Process process = Runtime.getRuntime().exec ("ipconfig");
InputStreamReader ir=new InputStreamReader(process.getInputStream());
BufferedReader input = new BufferedReader (ir);
String line;
StringBuffer str = new StringBuffer();
int exitVal = process.waitFor();
while ((line = input.readLine()) != null) {
String temp =line;
str.append(temp+"/r/n");
System.out.println(line);
//System.out.println(input.readLine());
}
System.out.println(exitVal);
System.out.println(str.toString());
}catch(Exception e){
System.err.println ("IOException " + e.getMessage());
}
}
为什么直接输出input.readline(),控制台输出的都是空呢?是传说中的缓冲区问题?赋值一下就可以了呢?
相关文章推荐
- java 调用oracle的函数出现的问题
- android js调用java 并取得java当中的返回值返回到js的做法其实很简单,打包后出现问题记得修改proguard.cfg文件
- C#调用java web Service出现的问题
- java调用MATLAB时出现的问题
- Java 调用 FFMPEG 命令时用 url 作为输入源,Linux 下出现 “no such file or directory” 问题的解决
- Iframe内部调用外部的location.href跳转出现奇怪问题
- 【转】用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!
- java 调用shell时出现假死问题
- ORACLE中调用JAVA类才出现ORA-29538、ORA-29532、ORA-29913问题解决
- java用jni调用dll动态库出现Can't find dependent libraries问题的解决方法
- Java基于Runtime调用外部程序出现阻塞的解决方法
- unity调用Android通过编译 java jar包出现问题解决和简单支付流程
- Quick-Cocos2d-x lua 调用java 在谷歌手机5.0 以上出现的问题处理方式
- java远程调用中出现的问题(主要是在不同电脑之间出现的问题)
- JAVA调用外部进程时,进程阻塞问题
- Java调用Dos批处理时出现的问题
- java调用控制台命令出现阻塞的解决方法
- android jni c/c++线程通过CallVoidMethod调用java函数出现奔溃问题
- 在服务中调用外部的窗体程序出现的问题(转载)
- 用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!