简体   繁体   中英

When does System.out not appear in the Java console?

I understood that anything to standard out ( System.out ) would appear in the Java Console window (when it's enabled). I spotted somewhere though that there might be situations where this isn't try, for example, from Swing apps. Is that the case?

Basically, what situations or setups wouldn't I expect to see standard output in the console? Is there a difference in behavior running on the JDK rather than explicitly on the JRE for example? javaw.exe?

ps, I understand how to display the Console in the Java settings but I'm curious as I've managed to create an application, run as an executable jar, that doesn't start the console despite some calls to System.out ) on Windows 7.

The only way you wouldn't see System.out output in the console is if the method System.setOut has been invoked. This method is invoked to redirect output to the graphical Java Console, but I don't know of any other realistic circumstance in which it would be redirected away from the Java Console unless you do so voluntarily.

Depending on terminal settings it can happen that the output is not written until a newline character is sent as well. So if you do System.out.print("test") it might not appear immediately. On Windows this is usually not the case, but on Unix terminals this is quite common.

Perhaps you use javaw to start virtual machine, this version will not show console messages. You can use java to start the virtual machine, which will show the console message.

javaw is intended for apps with windows, java is intended for console apps.

Same thing happened to me. I could not get System.out.println or Logger.debug either on console.

If you are on a huge project in Eclipse or whatever, you can read below.

Solution: I realized that I had not committed jars and some java files to SubVersioN on network. thats all. Project had not been compiled.

我可以想到的一种情况是调用System.setOut(null) (或System.setOut(any OutputStream other than System.out or System.err) ),那么控制台(如果存在)将不显示任何内容。

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