LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Left arrow button is not working in the ouput console (https://www.linuxquestions.org/questions/linux-newbie-8/left-arrow-button-is-not-working-in-the-ouput-console-848620/)

Sreevisakh 12-06-2010 05:51 AM

Left arrow button is not working in the ouput console
 
Hi,
I am new to Linux. I am having a java program which will read characters from console. i have started my program from bash shell and now the program starts and waiting for the inputs. Say I have typed text , "hello". If i try to move the cursor position back wards using the left arrow button it was not working. Instead some junk characters are printed on the console like ^[[C . Please see the out put text below.

hello^[[C^[[C^[[C^[[C^[[C
Below is my program.

public static void main(String as[]) {
BufferedWriter outputWriter =
new BufferedWriter(new PrintWriter(System.out));
BufferedReader inputReader =
new BufferedReader(new InputStreamReader(System.in));
String command = null;
try {


while (true) {
command = inputReader.readLine();
outputWriter.write("The command is " + command);
}
} catch (Exception e) {

}
}
}

Note: In windows its working fine.

Thanks in advance.
Sree

catkin 12-06-2010 06:08 AM

Does the left arrow key work at the console when your Java program is not running? What exactly is the console? What is the value of $TERM?

Sreevisakh 12-07-2010 06:52 AM

1 Attachment(s)
Quote:

Originally Posted by catkin (Post 4182102)
Does the left arrow key work at the console when your Java program is not running? What exactly is the console? What is the value of $TERM?

Thanks for the response. Yes the left arrow is functioning properly for the console when the program is not running. I have started the program from a bash shell. Here by console what I meant is the place where the output of the java program is displayed. This is actually the same bash shell from which the program runs. I have given an attachment which shows the output and terminal details here. Please see it.

Thanks,
Sree

catkin 12-07-2010 06:57 AM

Is the console a terminal emulator, a virtual terminal, a physical terminal on a serial port, running an ssh session ... ? The value of $TERM might help. What does the Java program do to read from the console? Which device does or file descriptor does it open and with which options? Do the other cursor movement keys all work OK?

ntubski 12-07-2010 09:07 AM

If you want line editing features like bash has you'll need something like Java Readline or JLine.

Sreevisakh 12-09-2010 12:06 AM

Quote:

Originally Posted by catkin (Post 4183388)
Is the console a terminal emulator, a virtual terminal, a physical terminal on a serial port, running an ssh session ... ? The value of $TERM might help. What does the Java program do to read from the console? Which device does or file descriptor does it open and with which options? Do the other cursor movement keys all work OK?

This program runs from a normal xterm terminal from a Linux machine. The java program starts and it will wait for the input texts the user enters into the console. The problem is there for all the movement keys. The program simply get the value from the console. It's not using any seperate file or device descriptor.

Thanks in advance,
Sree

prodev05 12-09-2010 12:43 AM

append "stty erase" in your shell profile and try re-login to your account.

Remember, in windows things will work fine except blue screen. But in Linux every thing will work better than what we expect. What we have to do is, we have to use our "BRAIN". With out practicing and understanding the concepts you can't work in Linux. Pl Don't consider this as rude.


Best Regards

Happy Programming.


All times are GMT -5. The time now is 04:58 AM.