简体   繁体   English

System.out如何在Eclipse中将输出直接定向到控制台?

[英]How does System.out direct output to console in eclipse?

While looking at somebody's maven Java project in eclipse, I noticed that one of saved run configurations has following maven command to run: 在eclipse中查看某人的maven Java项目时,我注意到保存的运行配置之一具有以下要运行的maven命令:

test -Dtest=fooTest -Dcom.awesomesite=System.out

When I inspected fooTest.java file, I noticed following statements: 当我检查fooTest.java文件时,我注意到以下语句:

public final static String BAR = "com.awesomesite";
....
this.whereToWrite = System.getProperty(BAR);

Obviously, an instance variable "whereToWrite" represents where the output data should go to. 显然,实例变量“ whereToWrite”表示输出数据应到达的位置。 Since I am beginner to Java, I just want to understand how does System.out direct output to be printed on console. 由于我是Java的初学者,所以我只想了解System.out如何将输出直接打印在控制台上。

System.out is connected to an environment/user specified display. System.out已连接到环境/用户指定的显示器。 The default happens to be the console. 默认碰巧是控制台。

When you launch a run configuration Eclipse starts a new process to run it using Runtime.getRuntime().exec(...) . 当启动运行配置时,Eclipse使用Runtime.getRuntime().exec(...)启动一个新进程来运行它。 This returns a Process object representing the new process. 这将返回代表新流程的Process对象。

Process has a getInputStream() method which returns an InputStream connected to the standard output of the process (which is where System.out normally writes). Process具有getInputStream()方法,该方法返回一个与流程的标准输出( System.out通常在此处写入)的InputStream连接。 Eclipse reads from this input stream and outputs what it receives on the console. Eclipse从此输入流中读取并输出其在控制台上接收到的内容。

Eclipse also reads from the process error stream using getErrorStream() . Eclipse还使用getErrorStream()从流程错误流中读取。

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

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