CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Unable to immediately access newly created file

 



whelan.pa
New User

Sep 6, 2002, 5:07 PM

Post #1 of 1 (514 views)
Unable to immediately access newly created file Can't Post

I have a problem with a Perl script running on NT where I have a script that is creating a file and then sometimes fails to be able to immediately open the file. The important snippet of code is as follows:

$

Code

|=1;

$LOGFILE = "$EVTMGT_LOGS" . "autoevent$$.log";

open (STDOUT, "| tee -a $LOGFILE");

#------------------------

# After this line are various prints to STDOUT and calls to other perl scripts

# that write to STDOUT

#----------------------

print "Sample line of output to STDOUT \n";



#-----------------------------------------------------------------

# Copy output from temporary autoeventpid.log file to end of full autoevent.log

#-----------------------------------------------------------------

close(STDOUT);

$old = "$EVTMGT_LOGS" . "autoevent$$.log";

$new = "$EVTMGT_LOGS" . "autoevent.log";

open(OLD, "< $old") or die "can't open $old: $!";

open(NEW, ">> $new") or die "can't open $new: $!";

while (<OLD>)

(print NEW $_) or die "can't write to $new: $!";

}

close(OLD) or die "can't close $old: $!";

close(NEW);

unlink "$old";




The issue is that infrequently the open(old, "< $old") line dies with the an error like "Can't open \var\opt\evtmgt\logfiles\autoevent999.log: No such file or directory..." I can eliminate 99% of the occurrences of the problem by adding a "sleep 5" after the close(stdout); statement but it still occurs from time to time. Any advice on why this might be happening? The requirement that I capture stdout from this perl script (as well as any modules called) to a log as well as display it to the calling program drove me to use the tee command in the stdout open. Open to any ideas.....

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives