Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 960423

Pages: 1
Anonymous
Unregistered




"Console"s and "Standard-I/O"
      #25784 - 01/10/06 01:03 PM

The article is interesting and informative, but I believe Sun's engineers should have thought harder before deciding to separate the Console from Standard Input/Output (System.in, System.out and System.err). Those familiar with Standard I/O (in UNIX, Windows and other operating systems) know that the Standard I/O files and the Console are synonymous -- at least when a program is started without I/O redirection -- and one can not exist without the other.

The first few lines of code in the article capture the irony of this separation succinctly:
Code:
Console console = System.console ();
if (console == null)
{
System.err.println ("Console not available");
return;
}


If you place these lines in a class packaged in an executable JAR (with a Main-Class entry in the manifest file), and start up the code by double-clicking the JAR file, the if statement will find no Console. But the message printed to System.err will mysteriously disappear as well! I believe in most situations where System.console() returns null, printing to System.err fails as well.

The System class has interesting features (such as setIn() and setOut()) that allow a program to redirect its standard I/O files while executing. But the initial configuration of these files (and how they differ from the I/O channel used by System.console()) should atleast be documented (by Sun) in greater detail.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 3967

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5