console window on Mac OS X

F

Felix Bertram

Dear Java Pros,

I would like to implement a simple console window based on JTextPane (or
similar) to emit Unix shell commands on Mac OS X. While I have found
reasonable examples how to implement the GUI part, I have severe trouble
in redirecting the input stream provided from the console window. I am
using code like this:

public ConsoleInThread(InputStream istream) {
super();
is= istream;
isr= new InputStreamReader(is);
br= new BufferedReader(isr);
}
public void run() {
try {
while ((line = br.readLine()) != null) {
System.out.println("*** ");
System.out.flush();
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
new ConsoleInThread(consolePane.getInputStream()).start();

The problem is, that I cannot see any of the commands entered into the
pane on the shell. When changing the inner loop to this snippet

while ((nextchar = is.read()) >= 0) {
System.out.println("*** " + nextchar);
System.out.flush();
}

things are working fine (however, I want line-wise input). Using
isr.read() already does not work and br.readLine() never worked for me.
What could be wrong? Could this be caused by differences in line
terminators on diffferend operating systems?



Any comments highly appreciated,
kindest regards


Felix
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top