aspose file tools*
The moose likes I/O and Streams and the fly likes How to capture diagnostics output continuously Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to capture diagnostics output continuously" Watch "How to capture diagnostics output continuously" New topic

How to capture diagnostics output continuously

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi Java Specialist,

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:

Output from Netbeans give:

BUILD SUCCESSFUL (total time: 0 seconds)

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

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.

Many thanks,

Joe Ess

Joined: Oct 29, 2001
Posts: 8867

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.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235

Thank you very much for your suggestions.


jQuery in Action, 2nd edition
subject: How to capture diagnostics output continuously