Is there a way to get a perl script to close all files handles and exit cleanly no matter what?
Seems like perl still realizes that somewhere down the line the java app is still running. And won't let me rename or change StartJava.pl.
Perl has an open file handle to the script if the script contains a __DATA__ or __END__.
While Perl gives up it's shared and exclusive lock on the file (allowing the file to be read and written by others), it doesn't give up the delete lock on the file (preventing others from deleting or renaming the file).
The solution is simple. As Corion told you in the CB, simply do close(DATA);
#!perl -l system qq{del "$0" >nul 2>&1}; print(-e $0 ? "not deleted" : "deleted"); close(DATA); system qq{del "$0" >nul 2>&1}; print(-e $0 ? "not deleted" : "deleted"); __DATA__
not deleted deleted
Even though the perl process and the cmd prompt which started it have both closed.
That's not possible. A process automatically relinquishes its file handles and file locks when it exits. Something else must have a lock on the file if Perl isn't running.
Update: Added code.
In reply to Re: Perl file handles
by ikegami
in thread Perl file handles
by CleverHanz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |