how to read chars from console [message #200621] |
Tue, 20 March 2007 07:01 |
Eclipse User |
|
|
|
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;
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.08161 seconds