Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

processing file while file is in use

by grashoper (Monk)
on Apr 21, 2009 at 12:51 UTC ( #758955=perlquestion: print w/replies, xml ) Need Help??

grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I am wondering how to go about capturing the output of an output file while another program is running, I have been able to open the file and it reads until it hits a pause then it seems to stop processing, I would like to take this file(s) contents which are being generated by mercury loadrunner and copy them to another file, primarily to check for errors. My thought is that I could search for transactions, and send a message alert if it either took to long or failed? my current loadrunner script does capture the times the transaction took, however loadrunner is set to continue on error and even if no authentication is performed it claims it performed the transactions, when I look at the log though I get messages like not authenticated and failed to retrieve etc. I get readline on closed filehandle INFO currently.
#!/usr/bin/perl use win32::OLE qw(in); use warnings; #$search="possible error text"; open(INFO, "E:\\Mibor_TimingTest\\Mibor\\output.txt"); open(OUT, "c:\\perl\\scripts\\counter.txt"); my @array=<INFO>; foreach $line(@array){ print (OUT "$line"); }close (INFO); close (OUT);

Replies are listed 'Best First'.
Re: processing file while file is in use
by gwadej (Chaplain) on Apr 21, 2009 at 13:12 UTC
      How could I capture from my logfile into a new file using this? I tried this but I think I need $name to be defined somewhere accidentally posted this the second call to file tail needed? I think they are just showing examples of usage..could I just open a new file where it reads and print to that new filehandle, open that file and do my process?
      use File::Tail; use win32::OLE qw(in); $file=File::Tail->new("E:\\mibor_timingtest\\mibor\\output.txt"); while (defined($line=$file->read)) { print "$line"; } use File::Tail; $file=File::Tail->new(name=>$name, maxinterval=>300, adjustafter=>7) +; while (defined($line=$file->read)) { open(OUT ">>", "c:\\test.txt"); print(OUT "$line"); } sub_do_something{ use win32::OLE qw(in); $search="stuff2searchfor"; open(OUT, "c:\\test.txt"); my @array=<INFO>; close (INFO); foreach $line(@array){ if ($line =~ /$search/) { print "found $line"; send alert }

        From the documentation, it looks like you use File::Tail to open the file in the reading process and read a line at a time.

        The module handles all of the housekeeping about the file being written to while you are reading it. There should be no reason for the writing process to change.

        G. Wade

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://758955]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2022-01-26 06:27 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.