简体   繁体   English

使用Java读取外部流程

[英]Read stream of an external process with Java

What I would like to know is, can I from Java read the output stream of an external process? 我想知道的是,我可以从Java中读取外部进程的输出流吗? Let us say this external process is a windows terminal and is not started from Java using ProcessBuilder or Runtime.exec(). 让我们说这个外部进程是Windows终端,不是使用ProcessBuilder或Runtime.exec()从Java启动的。

It is possible if the external process is a predecessor in a process pipeline: 如果外部流程是流程管道中的前身,则有可能:

> cat file | java MyClass

then java program can read the output stream of the cat program via System.in . 然后java程序可以通过System.in读取cat程序的输出流。 In other cases, I doubt it is possible even using C/C++ languages. 在其他情况下,我怀疑甚至可以使用C / C ++语言。

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

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