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; } }

In reply to Bad File Descriptor Error by digger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.