I would like to write a wrapper/terminal emulator to redirect the continuos output of a proprietary diagnostic utility, similar to the "top" command in Unix, where it refreshes it performance detail on the screen.
Let's have a look of the output from "top" on standard output would look like the following:
This "top" output is being displayed from either an X-Windows/Telnet emulation(Terminal setting - vt100).
Here is a few lines of code that attempt to capture these data and print it out through the Netbeans output windows:
As you can see, I have had little success with it so far. The above program worked for any one off output such as "ls", "ifconfig/ipconfig", etc.
I suspect that there is a way to use Java I/O to buffer these output data and regularly flushes it out but not sure how to go about getting it done. There may be 2 approaches to getting the data in, as far as my limited understanding goes:
( i ) regularly abort from running "top" & redirect the output to a file. ( ii ) continuously redirect all the data to a file every time the screen refreshes. You may suggest that I should try using certain switches/parameters provided by possibly "top". Unfortunately, this proprietary primitive diagnostic tool does not provide such functionality. It only displays the output on the standard output with the terminal environment variable set to (TERM=Wyse60).
I am fairly new to Java and would appreciate any guidances or different approaches to achieving the same purpose.
Java has notoriously poor support for the console. Java is intended to be cross-plaform, and there's no telling what the console will be (Windows CMD? Bash? ksh? No console at all (think set-top-box or phone)). You can get some control by using ANSI escape sequences, but you may need to do some work to activate them (and they will not work at all in something like Netbeans). Speaking of which, try removing the buffered reader, use plain read() and write() and run your app in a native console rather than Netbeans. I'm curious to know if your source application's method of clearing the screen (possibly ANSI control sequences) is propogated to your Java app's console.