Hi everyone. I'm new here. I have a question. I have a Perl script which runs perfectly in a Unix environment. However, when I run it in windows, I get an error that the temp file the script creates cannot be deleted because "Permission Denied". I tweaked my Windows permissions and gave every last user on my system full access to the temp directory where the temp files are created. I ran the script again and I still get permission denied. I seem to think that for some reason Windows or Perl is not honoring the close command I have in the script which causes the file to stay open and not be able to be deleted. The script creates the temp directory and files with no issues which means the script can write to the temp directory. It just can't delete the files it put there. The following is the snip of relevant code with some notes from me. My notes are in CAPS so you guys will know they are not part of the script. Thanks in advance for your help.
THIS WORKS WITHOUT ISSUE:
# create our temp file, $filename will contain the full path
my ($fh, $filename) = tempfile( DIR => $self->{Temp_Dir} );
THIS WORKS WITHOUT ISSUE:
# spew our mail into the temp file
my $SNF_fh = IO::File->new( $filename, "w" ) ||
die(__PACKAGE__ . ": Unable to create temporary file '" . $filename . "'");
THIS WORKS WITHOUT ISSUE:
$SNF_fh->print($mailtext) ||
$self->cleanup_die($filename,
__PACKAGE__ . ": Unable to write to temporary file '" .
$filename . "'");
THIS SEEMS WORKS WITHOUT ISSUE, BUT I'M NOT SURE. I'M NOT GETTING ANY ERRORS THAT SAYS IT'S NOT WORKING:
$SNF_fh->close ||
$self->cleanup_die($filename,
__PACKAGE__ . ": Unable to close temporary file '" .
$filename . "'");
THIS WORKS WITHOUT ISSUE:
#Change permissions.
my $cnt = chmod(0777, $filename) ||
$self->cleanup_die($filename, __PACKAGE__ .
": Unable to change permissions of temporary file '" .
$filename . "'");
THIS IS NOT WORKING. THIS IS WHERE I GET PERMISSION DENIED:
# Remove the temp file, we are done with it.
unlink ($filename) ||
$self->cleanup_die($filename,
__PACKAGE__ . ": Unable to delete temporary file '" .
$filename . "' because $!");
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.