Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » how to read chars from console
how to read chars from console [message #200621] Tue, 20 March 2007 07:01 Go to next message
Eclipse UserFriend
Originally posted by: yuyingtina.tom.com

I am working on an eclipse plugin about console.
I want to get chars from keyboard in the created console ,
and output it in the console.
the problem lies on the code
" IOConsoleInputStream stream = console.getInputStream();
byte[] b=new byte[5];
stream.read(b); //here is the problem "
the programm is hangging in this line.
Addition,I can write to the output stream and the text will appear on the
console.
but couldn't write and read chars from the keyboard.

Here is my code :


import java.io.*;
import org.eclipse.ui.console.*;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;

public class ConsoleViewPart implements IConsoleFactory {

private static IOConsole console = new IOConsole("IOconsole",
null,null);

public void openConsole() {
showConsole();
}

public static void showConsole() {

if (console != null) {

IConsoleManager manager =
ConsolePlugin.getDefault().getConsoleManager();

IConsole[] existing = manager.getConsoles();
boolean exists = false;
for (int i = 0; i < existing.length; i++) {
if (console == existing[i])
exists = true;
}
if(!exists){
System.out.println("hello");
manager.addConsoles(new IConsole[] { console });
}
manager.showConsoleView(console);
}


try {
IOConsoleInputStream stream = console.getInputStream();
byte[] b=new byte[5];
stream.read(b); // here is the problem
IOConsoleOutputStream out=console.newOutputStream();
out.write(b);
System.setOut(new PrintStream(out));}
catch (IOException e) {
e.printStackTrace();
}
}



public static void closeConsole() {
IConsoleManager manager =
ConsolePlugin.getDefault().getConsoleManager();
if (console != null) {
manager.removeConsoles(new IConsole[] { console });
}
}

public static IOConsole getConsole() {
return console;
}

}
Re: how to read chars from console [message #200646 is a reply to message #200621] Tue, 20 March 2007 11:46 Go to previous message
Eclipse UserFriend
Originally posted by: yuyingtina.tom.com

I'm waiting for you to help me ,thanks!
Previous Topic:Getting diff of changes per checkin on Eclipse CVS repository ?
Next Topic:Any plugin for bash scripting?
Goto Forum:
  


Current Time: Thu Apr 25 01:23:51 GMT 2024

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

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

Back to the top