canedandunable
Programmer
Hi,
I don't use Perl that often except to generate text files for testing of embedded systems. I currently have an application that creates a file which is emitted to a system which provides a reply. I parse the reply and check against what was sent. In the meantime, I append a log file with results from the operation.
It is the log file which is causing a problem and I think it has to do with file locking and Windows 98.
The code which appends the log file is:
sub AppendLogFile
{
my $StringToWrite = shift;
my $filehandle = new IO::File;
$filehandle->open(">>$LogFilename"
or die "No such file : $LogFilename\n\r";
my $timestr;
my @dantime = localtime();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$timestr = "";
$timestr .= sprintf("%02d", $hour).":";
$timestr .= sprintf("%02d", $min).":";
$timestr .= sprintf("%02d", $sec)." ";
$timestr .= sprintf("%02d", $mday)."/";
$timestr .= sprintf("%02d", $mon);
if($StringToWrite eq "BLANK"
{
$filehandle->print("\n\r"
or print "Unable to write blank line to file $LogFilename\n\r";
print "\n\r";
}
else
{
$filehandle->print($timestr." : ".$StringToWrite."\n\r"
or print "Unable to write data to $LogFilename\n\r";
print $timestr." : ".$StringToWrite."\n\r";
}
$filehandle->close();
}
which is called as:
AppendLogFile("Some message"
;
It seems that after a while, Windows decides that the file is in use and won't allow Perl to write any more data to it; attempting to delete the file via the OS warns that the file is in use by the OS.
So, it would seem that Perl is not closing the file properly when it has been finished with. Is there some mechanism I need to employ to overcome this?
I have used the same code on a Linux box with no problems in the past.....
Regards,
Dan
I don't use Perl that often except to generate text files for testing of embedded systems. I currently have an application that creates a file which is emitted to a system which provides a reply. I parse the reply and check against what was sent. In the meantime, I append a log file with results from the operation.
It is the log file which is causing a problem and I think it has to do with file locking and Windows 98.
The code which appends the log file is:
sub AppendLogFile
{
my $StringToWrite = shift;
my $filehandle = new IO::File;
$filehandle->open(">>$LogFilename"

my $timestr;
my @dantime = localtime();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$timestr = "";
$timestr .= sprintf("%02d", $hour).":";
$timestr .= sprintf("%02d", $min).":";
$timestr .= sprintf("%02d", $sec)." ";
$timestr .= sprintf("%02d", $mday)."/";
$timestr .= sprintf("%02d", $mon);
if($StringToWrite eq "BLANK"

{
$filehandle->print("\n\r"

print "\n\r";
}
else
{
$filehandle->print($timestr." : ".$StringToWrite."\n\r"

print $timestr." : ".$StringToWrite."\n\r";
}
$filehandle->close();
}
which is called as:
AppendLogFile("Some message"

It seems that after a while, Windows decides that the file is in use and won't allow Perl to write any more data to it; attempting to delete the file via the OS warns that the file is in use by the OS.
So, it would seem that Perl is not closing the file properly when it has been finished with. Is there some mechanism I need to employ to overcome this?
I have used the same code on a Linux box with no problems in the past.....
Regards,
Dan