简体   繁体   中英

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:

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

When I inspected fooTest.java file, I noticed following statements:

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. Since I am beginner to Java, I just want to understand how does System.out direct output to be printed on console.

System.out is connected to an environment/user specified display. 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(...) . This returns a Process object representing the new 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). Eclipse reads from this input stream and outputs what it receives on the console.

Eclipse also reads from the process error stream using getErrorStream() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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