6

When I use System.console from Eclipse Helios, it always returns null.

However, when I use it directly from command line (i.e. compiling and executing a java source code manually from command prompt), I do get a Console object.

To know, why this happens I checked this link. According to it, when I run my Java code from Eclipse, a background job scheduler must be starting my JVM. What does this mean?

And how differently is my JVM started when I start it from command line?

I also checked this link. Here McDowell says that cmd.exe is a console device. So then I am again confused that exactly is a console device?

whitehat
  • 2,381
  • 8
  • 34
  • 47
  • 1
    you can find your answer from this thread http://stackoverflow.com/questions/104254/java-io-console-support-in-eclipse-ide – Prateek Sharma Jan 23 '12 at 10:27

2 Answers2

6

Because it is a bug #122429 of eclipse

thiagoh
  • 7,098
  • 8
  • 51
  • 77
2

System.console() returns null if there is no console.

You can work round this either by adding a layer of indirection to your code or by running the code in an external console and attaching a remote debugger.

Also, According to the docs:

If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.

Community
  • 1
  • 1
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276