digger has asked for the wisdom of the Perl Monks concerning the following question:
Esteemed Monks,
I have run into a strange problem that I can't seem to get to the bottom of on my own, so I come to the monestary seeking assistance.
I have a script that watches a directory, and modifies some files before moving them to an output directory. Fairly simple, and I have done similar work before without any problems. This time I am getting a bad file descriptor error when creating the output file. I have tried File::Copy, Win32::CopyFile and simply writing the data to the file during processing, and I get the same error each time. The really strange part is that when I use File::Copy or Win32::CopyFile, I get the output file as requested along with the error. When I use the standard print FILE $data, the write fails and I get no file.
Thanks for any assistance/pointers,
digger
open(FILE,"<",$file); binmode(FILE); if (flock(FILE,LOCK_EX|LOCK_NB)) { my $buf = ""; report("Info: Processing $file"); #make sure this is a pcl job file first #if not, move it and log it read(FILE,$buf,9); $printstring = $printstring.$buf; unless($buf =~ m/^\x1B\x25\x2D\x31\x32\x33\x34\x35\x58 +/) { close(FILE); my $errdir = "$dir\\ERR"; report ("Warning: $file is not a valid PCL file - +moving to ERR folder"); unless(-d $errdir){mkdir($errdir);} move($file,$errdir); next; } while(read(FILE,$buf,4096)) { fixtraycalls(\$buf); $printstring= $printstring.$buf; } close FILE;#closing file flushes buffer and releases l +ock if($keepfile) { my $dest; sleep 1; eval{ $dest = $$appconfig{"destination"}."\\$filenam +e"; Win32::CopyFile($file,$dest,1); }; if($!) { report("Error: Unable to move file to destinat +ion - ".$dest."\n $!"); #die; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bad File Descriptor Error
by Anno (Deacon) on Mar 19, 2007 at 17:20 UTC | |
by digger (Friar) on Mar 20, 2007 at 13:18 UTC | |
by Anno (Deacon) on Mar 20, 2007 at 14:58 UTC | |
by Bro. Doug (Monk) on Mar 20, 2007 at 18:26 UTC | |
|
Re: Bad File Descriptor Error
by samtregar (Abbot) on Mar 19, 2007 at 17:12 UTC | |
|
Re: Bad File Descriptor Error
by Moron (Curate) on Mar 19, 2007 at 16:53 UTC | |
|
Re: Bad File Descriptor Error
by bingos (Vicar) on Mar 20, 2007 at 08:21 UTC |