【发布时间】:2012-02-11 07:38:56
【问题描述】:
我正在从流程流中读取数据。基本上,我使用 Runtime.exec API 运行进程并获取进程输入流。
Runtime rt = Runtime.getRuntime();
process = rt.exec("C:/cygwin/home/grec.exe");
InputStream is = process.getInputStream();
然后我将进程的输出收集为 --
BufferedReader in = new BufferedReader(is);
char[] ls = new char[s.available()];
ls.read(ls);
String output = new String(ls);
但是,当我打印字符串输出时,我得到了 --
break [loc] Add a breakpoint at [file:]line or template
callflow [val] Enable call flow tracing
next Execute the over instruction, stepping over calls
over Execute the current instruction hierarchy
但实际输出是--
break [loc] Add a breakpoint at [file:]line or template
callflow [val] Enable call flow tracing
next Execute the over instruction, stepping over calls
over Execute the current instruction hierarchy
print <xpath> Print the value of an XPath expression
profile [val] Turn profiler on or off
reload Reload the script contents
run Restart the script
step Execute the next instruction, stepping into calls
verbose Turn on verbose (-v) output logging
where Show the backtrace of template calls
quit Quit debugger
也就是说,输出的一部分被截断,但代码没有抛出异常。我尝试增加 BufferedReader 的大小并增加数组 ls 的大小。我无法找到这种行为的原因。任何关于可能是什么原因的提示或指示将不胜感激。
【问题讨论】:
-
您的代码示例中的
s是什么?也许我忽略了一些东西,但是怎么样:OutputStream out = process.getOutputStream(); BufferedReader bufferedOut = new BufferedReader(out); -
其实我在做同样的事情。这就是我正在做的——
-
这里实际上s代表InputStream。即--InputStream s = process.getInputStream();
-
为什么不使用
in.readline()?为什么要创建 char 数组?
标签: java process stream io inputstream