Hi all,
We have an application which writes temporary files to a directory. These files are typically open and being written to by that application for about 3 seconds and then they are deleted and another temp file is opened and written with the same filename. They are deleted because as soon as the file is complete it prints (It is a zebra printer file).
I am trying to write a script which will capture all the information in the file before it is deleted by the application. The reason I want to do this is so that I can reprint it if necessary. The file is written by a database and the application that tries to do reprints often takes 2.5 minutes to reprint one label. This is a big problem if you have to reprint 100 labels!!! The database people say that they have done all they can to optimize the reprint time and the application people won't change it to save the file anywhere else permanently so I gotta hack it myself. If I can capture this label file before it prints, then I will have a permanent copy which I can print at any time and I could select 100 of them and reprint them all in 1 second!!!
The problem is knowing when the file is complete. I have written this snippet of code to find out if the eof() function would work, but it is fooled into thinking that the end of file is just the most recent line written to the file.
while (1) {
$dir="c:\labels";
opendir DIR, $dir or die "Can't open $dir: $!\n";
while ($file = readdir DIR) {
$in_file_path="$dir\\$file";
if ($file=~/^tmp/ig) {
open IN, "$in_file_path" or die "Can't open $in_file_path: $!\n";
while (<IN>) {
if (eof) {
print "End of file is $. $_\n";
}
}
close IN;
}
}
}
The results show the file building like so:
"End of file is 60 $_stuff"
"End of file is 63 $_stuff"
"End of file is 67 $_stuff"
"End of file is 75 $_stuff"
"End of file is 77 $_stuff"
"End of file is 78 $_stuff"
So you can see that eof() doen't work and there is nothing written to the end of the file to let you know that the end has been reached. The zebra language has end of label syntax, but this is used more than once in the label file.
These files are always less than 6k and sometimes only 2k, so they don't stick around long. I tried to find a function which will tell me if the file is open by another application, but I've had no luck. Anyone here have any ideas?
Thanks a million. I'm just a beginning perl hacker, so excuse me if this is simple.
Shagy
We have an application which writes temporary files to a directory. These files are typically open and being written to by that application for about 3 seconds and then they are deleted and another temp file is opened and written with the same filename. They are deleted because as soon as the file is complete it prints (It is a zebra printer file).
I am trying to write a script which will capture all the information in the file before it is deleted by the application. The reason I want to do this is so that I can reprint it if necessary. The file is written by a database and the application that tries to do reprints often takes 2.5 minutes to reprint one label. This is a big problem if you have to reprint 100 labels!!! The database people say that they have done all they can to optimize the reprint time and the application people won't change it to save the file anywhere else permanently so I gotta hack it myself. If I can capture this label file before it prints, then I will have a permanent copy which I can print at any time and I could select 100 of them and reprint them all in 1 second!!!
The problem is knowing when the file is complete. I have written this snippet of code to find out if the eof() function would work, but it is fooled into thinking that the end of file is just the most recent line written to the file.
while (1) {
$dir="c:\labels";
opendir DIR, $dir or die "Can't open $dir: $!\n";
while ($file = readdir DIR) {
$in_file_path="$dir\\$file";
if ($file=~/^tmp/ig) {
open IN, "$in_file_path" or die "Can't open $in_file_path: $!\n";
while (<IN>) {
if (eof) {
print "End of file is $. $_\n";
}
}
close IN;
}
}
}
The results show the file building like so:
"End of file is 60 $_stuff"
"End of file is 63 $_stuff"
"End of file is 67 $_stuff"
"End of file is 75 $_stuff"
"End of file is 77 $_stuff"
"End of file is 78 $_stuff"
So you can see that eof() doen't work and there is nothing written to the end of the file to let you know that the end has been reached. The zebra language has end of label syntax, but this is used more than once in the label file.
These files are always less than 6k and sometimes only 2k, so they don't stick around long. I tried to find a function which will tell me if the file is open by another application, but I've had no luck. Anyone here have any ideas?
Thanks a million. I'm just a beginning perl hacker, so excuse me if this is simple.
Shagy