Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Connecting IOConsole to an invoked Process
Connecting IOConsole to an invoked Process [message #757181] Thu, 17 November 2011 01:18 Go to next message
Shahin  is currently offline Shahin Friend
Messages: 2
Registered: November 2011
Junior Member
What I an trying to do is the following:
I have an external program which I want to invoke via Eclipse. For simplicity, let's assume my program takes commands line like "2 + 3" and returns the result. So, I do not need to create a Launch Configuration (at least not right now). I have been able to invoke and program and have its output (its greeting) to be displayed on an IOConsole, but I have not been able to figure out how to get the keyboard streaming from the console back to the my external program.
I have been hoping that there would be an easy-to-use API to connect an external process to a Console in Eclipse and have both Input and Output streams work flawlessly. I guess the answer is No.
Can anyone help me with this? Ideally it would be great if you can provide me with a complete example for both streams between the external process and an eclipse IOConsole.
Thanks
Re: Connecting IOConsole to an invoked Process [message #757336 is a reply to message #757181] Thu, 17 November 2011 18:54 Go to previous message
Shahin  is currently offline Shahin Friend
Messages: 2
Registered: November 2011
Junior Member
Well, here is my own solution. It works, it is not my ideal solution though.

public class IOConsoleKeyboardReader extends Thread {
private IOConsoleInputStream stream;
private ArrayList<IOConsoleKeyboardReaderListener> listeners = new ArrayList<IOConsoleKeyboardReaderListener>();
private boolean keepRunning;

public IOConsoleKeyboardReader(IOConsole console) {
stream = console.getInputStream();
}

public void addListener(IOConsoleKeyboardReaderListener l) {
listeners.add(l);
}

public void removeListener(IOConsoleKeyboardReaderListener l) {
listeners.remove(l);
}

public void finish() {
keepRunning = false;
}

public void run() {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String command;
keepRunning = true;
while ( keepRunning ) {
try {
command = reader.readLine();
for (IOConsoleKeyboardReaderListener l: listeners) {
l.onTextReceived(command);
}
Thread.sleep(20);
} catch (Exception e) {
//e.printStackTrace();
}
}
}


public interface IOConsoleKeyboardReaderListener {
public void onTextReceived(String text);
}
}
Previous Topic:How to extend the view part popup menu
Next Topic:Error Log and console output
Goto Forum:
  


Current Time: Thu Apr 25 04:28:53 GMT 2024

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

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

Back to the top