java.lang.Process.getErrorStream()方法实例:java.lang.Process.getErrorStream() 方法获取子进程的错误流。数据流获取由该Process对象表示的进程的错误输出流的管道的数据。
Process
ps = null;
ps
= Runtime.getRuntime().exec(command);
final InputStream errorStream = ps.getErrorStream();
final InputStream errorStream = ps.getErrorStream();
Java Process.getOutputStream()方法用法实例教程,得到子进程的输出流。由该Process对象表示的进程的标准输入流的管道输送到输出流中.
StringBuilder
buf = new StringBuilder();
String line = null;
ps.getOutputStream().close();
while ((line = errorBuf.readLine()) != null) {
buf.append(line);
}
ps.waitFor();
String errorStr = buf.toString();
String line = null;
ps.getOutputStream().close();
while ((line = errorBuf.readLine()) != null) {
buf.append(line);
}
ps.waitFor();
String errorStr = buf.toString();
本文介绍如何使用Java的Process类来获取子进程的错误流及输出流,并提供了具体的代码实例。通过Runtime类执行命令,获取子进程,进而读取其错误流内容。
16万+

被折叠的 条评论
为什么被折叠?



