Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » System.console() returns null in Eclipse but works from command line
System.console() returns null in Eclipse but works from command line [message #245438] Tue, 10 July 2007 09:55 Go to next message
Eclipse UserFriend
Originally posted by: sirko.rudolph.gmx.net

Hi,
this question was asked in the new users group last September but never
answered.

So I hope here is somebody who can help solving this problem.

In a very simple Java class I make a call to System.console() to get a
Console object. However, if I run the program in the Eclipse IDE the
System.console() returns null. If I run the same program from the command
line I actually get a Console instance and can work with it (e.g. using
the Reader() from the Console object).

Where can the problem be? I checked the run settings that "Allocate
Console" is checked. Also, if I just use System.in to get input from the
console it is working within the IDE but not with System.console().

Any hints would be highly appreciated.

I am using Eclipse 3.2.2, Build M20070212-1330

Thanks in advance,
Sirko
Re: System.console() returns null in Eclipse but works from command line [message #245453 is a reply to message #245438] Tue, 10 July 2007 10:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pgodeau_nosp.m_sapex-alma.com

Sirko a écrit :
> In a very simple Java class I make a call to System.console() to get a
> Console object. However, if I run the program in the Eclipse IDE the
> System.console() returns null. If I run the same program from the
> command line I actually get a Console instance and can work with it
> (e.g. using the Reader() from the Console object).

Hi,

This is not surprising. RTFM:

http://java.sun.com/javase/6/docs/api/java/io/Console.html

"Whether a virtual machine has a console is dependent upon the
underlying platform and also upon the manner in which the virtual
machine is invoked. If the virtual machine is started from an
interactive command line without redirecting the standard input and
output streams then its console will exist and will typically be
connected to the keyboard and display from which the virtual machine was
launched. If the virtual machine is started automatically, for example
by a background job scheduler, then it will typically not have a console.
....
If no console device is available then an invocation of that method will
return null."
Re: System.console() returns null in Eclipse but works from command line [message #245672 is a reply to message #245453] Fri, 13 July 2007 05:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sirko.rudolph.gmx.net

Hi,

thanks for the answer. Forgive me that I bother all of you again. But I
did read exactly this excerpt from the Javadocs. What I do not know is
what Eclipse does in the background when launching a program in the IDE.

So for me it seams, that Eclipse is redirecting the standard input and
output. Therefore the simple "new Scanner( System.in )" is working in the
IDE because it's using the (redirected) InputStream of the IDE, while a
Console object is not existing in the IDE.

Is that right?

Thanks all for your patience.

Regards
Sirko
Re: System.console() returns null in Eclipse but works from command line [message #245855 is a reply to message #245672] Mon, 16 July 2007 12:21 Go to previous message
Eclipse UserFriend
If you launch a java program from the command line that launches a java
program, is the console available from the nested program? This is
effectively what the run/debug support does in Eclipse, so I would expect
the same behavior.

Darin Wright

"Sirko" <sirko.rudolph@gmx.net> wrote in message
news:226fb0e3cd311e991f3962322a1bf6bc$1@www.eclipse.org...
> Hi,
>
> thanks for the answer. Forgive me that I bother all of you again. But I
> did read exactly this excerpt from the Javadocs. What I do not know is
> what Eclipse does in the background when launching a program in the IDE.
>
> So for me it seams, that Eclipse is redirecting the standard input and
> output. Therefore the simple "new Scanner( System.in )" is working in the
> IDE because it's using the (redirected) InputStream of the IDE, while a
> Console object is not existing in the IDE.
>
> Is that right?
>
> Thanks all for your patience.
>
> Regards
> Sirko
>
Previous Topic:Adding links in Console View
Next Topic:problem while refactoring a cvs project
Goto Forum:
  


Current Time: Tue Sep 23 11:21:45 EDT 2025

Powered by FUDForum. Page generated in 0.04406 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top