Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying live results of a logfile in a window

Status
Not open for further replies.

jpasquini

Programmer
Apr 20, 2006
44
US
Hi All,

I'm wondering if anyone has seen a good example of this out there somewhere.

I am calling a program from within a PERL script using a system call:
system ( "run_program 1>LOGFILE" )

The program writes entries to the logfile, and takes about 5 min or so.


What I want to do is have a display window in the Perl "form" which scrolls the logfile, as info is being dropped in there.

Right now I can dump the logfile to a window, but it isn't "live":

################################################
### This subroutine creates a scrolled window
### which displays the contents of the
### releaseLOG file.
###
### Usage: '&show_log'
###---------------------------------------------

sub show_log
{
open FILE, "${batch_script_directory}LOGFILE" || die "release: ?Can't open the log for reading. $!";

while (<FILE>)
{
chomp;

my $logfile_l = $title_b-> Label (
-text=> $_,
-font => "{Arial} 11 {bold}",
-foreground=> 'black',
-height=> 1,
-width=> 5,
-relief=> 'ridge',
)-> pack (
-side=> 'left',
);

}
#
#
MainLoop;
#
#$logfile_l-> destroy();
#
}


 
Look up File::ReadBackwards on
Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Paul,

I'm not sure if this is what I'm looking for. At least, I assume first that you are supposed to take the ReadBackwards.pm module out of the download, reference it in your program, and then call it on a file. It didn't work for me it wasn't able to read the log file.

What I need is some additional branch within the command:

SYSTEM ( "command 1> LOGFILE" );

to also "tee" the output to a Perl window on the screen as it is being written. Like one would assume:

SYSTEM ( "command 1> LOGFILE | tee $info_window" )

$info_window being a Perl object.


Secondly, NEVER accidentally hit the ESCAPE key, located conveniently close to the TAB key, when writing a post. It will instantly wipe out everything.
An extra feature added to keep people like me on their toes............


jpasquini
 
Apologies, drive by posting.

File::ReadBackwards perhaps isn't the most appropriate tool for this.

Code:
use File::ReadBackwards ;
    $bw = File::ReadBackwards->new( 'log_file' ) or                        die "can't read 'log_file' $!" ;
    while( defined( $log_line = $bw->readline ) ) {
            print $log_line ;
    }[code]  but as the man says, it's so crazy, it just might work.  Where the 'print $log_line;' line is, if you had a conditional to check the value of $last_printed_line, and if no match, push it onto an array to print, else print array.  And call the function again, until end of process ... not sure how efficient this would be though

had this a while ago where the tail function isn't so portable.  What's the command doing?  You may be able to redirect to STDERR, and Select STDERR to read from within your program, but that's a bit beyond my skills at present ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
The verdict has come down that ReadBackwards is a nonstandard module and is to be therefore forever forbidden and shunned. I am no longer allowed to think about ReadBackwards.

The command is basically running a bunch of stuff, and then dropping the results line by line into a logfile. "Read xxxx, Performed yyyyy, Return Status 0".

The problem is, if it's a system call, Perl waits for it to finish before it can update any display window.
I thought about trying to run the system command in the background, maybe? Still tinkering. The resident guru mentioned "fork processing" but then he left for the day. Since I work until 7:30 tonight, it'd probably be a good idea to solve it before tomorrow..........*sigh*

1st law of Contracting- Always know everything in advance of learning it

 
CPAN, the contractors friend ...
File::Tail should be all you need, and take no guff for non standard, CGI.pm only became a standard module as of Perl 5.6, they all have to start somewhere ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Paul,

An excellent module. However, we don't have it. Unfortunately every module that doesnt' come with the current purchased version would have to go across reams of desks and rubber stamps. Envision something like getting a bill through Congress.......it's a huge company.

I could email up the line, with the comment "I'm not taking any guff!!!" and strike out on my own. I imagine sometime afterwards my magnetic nametag would be unclunked and my cubicle in the hive cleaned out. This would also solve the problem I suppose............

 
It helps to audit the module yourself, you could even pick it apart to do what you need, but then that's more maintenance.

The greatest continuing beauty of Perl is CPAN, loads and loads of modules, already written, open source.

If you handed up a printout of the module, along with testplans, etc, etc, that'd surely be the express route. Even flag it as an attempt at a company record, and where it sticks, there'll be the people who need to validate their existence ...

I'd start by downloading the module onto a testbox, and then look at how it works and reapplying that to your own project. no module required, but prone to more maintenance ...

Your call ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Look into opening a pipe from the called program. You could pipe the output from the called program to your own, display it and write it to the logs as you go.

Sorry I don't have any sample code handy on doing the pipes It goes something like this
Code:
# replace this line with working code
open( MYPIPE, `command |`);
while<MYPIPE> {
    #print to log
    # print to screen
}

if you need to capture stderr as well it might be
Code:
open( MYPIPE,  `command 2>&1 |`);
instead


Jeb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top