Hi,

First of all, this is my first proper post for help on this forum, so hello to everyone! It's good to be here!

Now, down the business...

I have a problem with a command-line application which emulates an SQL DBMS environment. (not really that important to the problem per se, but it might give you some scope and perspective...)

The problem I have concerns the ability to intercept the user's action of pasting several commands (composed of several lines) from their clipboard into the Java's input. I'll use the following example:

If I have the following string in the clipboard:
"select * from example;\r
select * from example;\r
select * from example;\r"

...where '\r' is the return character to execute the command...

...and i paste it into the console at the prompt, then we get the following in each scenario:

==========================
THIS IS HOW ANY SQL DBMS DISPLAYS IT:
==========================
prompt> select * from example;
 col1 |  col2
------+--------
    1 | Value1
    2 | Value2
    3 | Value3
(3 rows)
 
prompt> select * from example;
 col1 |  col2
------+--------
    1 | Value1
    2 | Value2
    3 | Value3
(3 rows)
 
prompt> select * from example;
 col1 |  col2
------+--------
    1 | Value1
    2 | Value2
    3 | Value3
(3 rows)
==========================

...this is the normal output that I wish to achieve...

but...

==========================
THIS IS HOW JAVA DISPLAYS IT:
==========================
prompt> select * from example;
select * from example;
select * from example;
 
 col1 |  col2
------+--------
    1 | Value1
    2 | Value2
    3 | Value3
(3 rows)
 
 col1 |  col2
------+--------
    1 | Value1
    2 | Value2
    3 | Value3
(3 rows)
 
 col1 |  col2
------+--------
    1 | Value1
    2 | Value2
    3 | Value3
(3 rows)
==========================

...so the difference being that Java simply allows all 3 commands to be
"visible" (printed) on the terminal screen before executing each command, which doesn't look good! I'm currently using a BufferedReader which wraps an InputStreamReader to do the job.

Here's the code I use to read...
...
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
 
while (running == true) {
 
    try {
        System.out.print("prompt> ");
        command = inputReader.readLine();
        ...
       // Some SQL-related parsing
        ...
        executeCommand(command);
    } catch (IOException e) {
        System.out.println("ERROR Reading Input. Please try again!");
    }
 
}
...

I suspect that the terminal window does what it wants with the input before passing it to Java to handle, hence it simply prints the string, but perhaps it is possible with a different class other than BufferedReader and InputStreamReader....??

Any thoughts on this matter would be greatly appreciated.

Thanks in advance!