Hello all,
I am trying to create a lockfile in my program to ensure only one instance is running at a time. I'm having some troubles getting my logic working. Here is my code:
The output I get EVRYTIME I run the program is:
It seems so simple I want to create the lockfile and if the program completes ok I want to delete it. But the file is never created and so never deleted!
If at first you don't succeed, don't try skydiving.
I am trying to create a lockfile in my program to ensure only one instance is running at a time. I'm having some troubles getting my logic working. Here is my code:
Code:
#!c:\\perl\\bin\\perl
use strict;
use warnings;
my $lock_file = "D:\\Stage\\lockfile";
if (-e $lock_file) {
print "Found lock file $lock_file.
exit 1;
}
open (LOCK, "+>$lock_file")or die ("Error opening $lock_file $1");;
print LOCK "print some junk\n";
close LOCK;
print "$lock_file\n";
if (unlink($lock_file) == 0) {
print "File deleted successfully.";
} else {
print "File was not deleted.";
}
The output I get EVRYTIME I run the program is:
Code:
D:\Stage\lockfile
File was not deleted.
It seems so simple I want to create the lockfile and if the program completes ok I want to delete it. But the file is never created and so never deleted!
If at first you don't succeed, don't try skydiving.