#143 System.console ()

open
nobody
5
2006-11-28
2006-11-28
Anonymous
No

The following code was run JDK 1.6.0-rc-b104 and DrJava 20060821-1502.

import java.io.Console;

public class Main
{
public static void main(String[] args)
{
Console console = System.console();
if(console != null)
{
String name = console.readLine("[Please Provide Your Name]: ");
}
else
{
throw new RuntimeException("Can't run w/out a console!");
}
}
}

System.console() is returning null. Since DrJava has a colsole window, shouldn't a valid Console object be returned?

Discussion

  • Dan Smith

    Dan Smith - 2006-11-28

    Logged In: YES
    user_id=1060117
    Originator: NO

    For our future reference, the relevant documentation on java.io.Console is here:
    <http://java.sun.com/javase/6/docs/api/java/io/Console.html>

    This text from the documentation is relevant: "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."

    I'm not familiar with the new Console facility, so I can't be much help at this point. We run the Interactions pane by executing a process with "Runtime.exec()". We use the facilities provided by java.lang.Process to access its input and output streams. I don't know if it is possible to tie these streams into the Interactions JVM's console. We will have to explore this further.

     
  • Mathias Ricken

    Mathias Ricken - 2006-11-29

    Logged In: YES
    user_id=1075744
    Originator: NO

    This is available ONLY in the beta of Java 6. I'm sure we'll make an effort to support this, but we'll have to be careful to not sacrifice compatibility with our Java 5 user base.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks