简体   繁体   English

java新过程-从ErrorStreams和Output流获取和读取它是必需的

[英]java new process - is necessary to get and read from ErrorStreams and Output streams

I create new process from a java code using ProcessBuilder 我使用ProcessBuilder从Java代码创建新流程

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? 是否有必要获取OutputStream和ErrorStream? Is it automatically ignored? 是否会自动忽略?

Output may be large (10MB) -- in some cases. 输出可能很大(10MB)-在某些情况下。

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. 如果您知道正在创建的进程不会对stdout或stderr产生太多(或任何)输出,那么您可能还可以,否则您应该创建线程来读取和丢弃每个流的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM