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
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