java 新进程 - 需要从 ErrorStreams 和输出流中获取和读取
我使用 ProcessBuilder 从 java 代码创建新进程
ProcessBuilder builder = new ProcessBuilder("/path/to/bin");
Process process = builder.start();
在这种情况下,我对查看错误/输出不感兴趣。是否有必要抓取OutputStream和ErrorStream?会自动忽略吗?
在某些情况下,输出可能很大(10MB)。
I create new process from a java code using ProcessBuilder
ProcessBuilder builder = new ProcessBuilder("/path/to/bin");
Process process = builder.start();
In this case, I am not interested in seeing error/output. Is it necessary to grab OutputStream and ErrorStream? Is it automatically ignored?
Output may be large (10MB) -- in some cases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要对这些流执行任何操作,但您应该注意,如果输出缓冲区已满,创建的进程可能会阻塞。如果您知道您正在创建的进程不会向 stdout 或 stderr 产生太多(或任何)输出,那么您可能没问题,否则您应该创建读取并丢弃每个流的输出的线程。
You're not required to do anything with those streams, but you should be aware that the created process may block if the output buffers become full. If you know that the process you are creating does not produce much (or any) output to stdout or stderr then you're probably OK, otherwise you should create threads that read and discard the output from each stream.