Go Back   Java Programming Forums > Java Standard Edition Programming Help > File I/O & Other I/O Streams


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2010, 10:47 PM
Junior Member
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Nilhanth is on a distinguished road
Default Problem with Console Input from Clipboard

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:
==========================
Java Code
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:
==========================
Java Code
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...
Java Code
...
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!



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing output from console to .html RSYR File I/O & Other I/O Streams 6 10-12-2009 11:55 PM
printing output to console & to a text file at the same time... prasanna File I/O & Other I/O Streams 3 26-08-2009 08:43 AM
[SOLVED] help with console input strnig.... mdstrauss File I/O & Other I/O Streams 5 17-08-2009 08:59 AM
How to Read user input from the console with the Scanner class JavaPF Java Code Snippets and Tutorials 0 11-11-2008 06:47 PM
How to Read user input from the console with InputStreamReader JavaPF Java Code Snippets and Tutorials 0 19-05-2008 11:48 AM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:58 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.