in reply to Is the program there? (W32)
Here's another way using a semaphore.
#! perl -slw use strict; use Win32::Semaphore; ( my $semName = $0 ) =~s[\\][/]g; die 'Program already running' if Win32::Semaphore->open( $semName ); my $sem = Win32::Semaphore->new( 1, 1, $semName ) or die $^E; sleep 1000; __END__ c:\test>start /b loner.pl c:\test>loner.pl Program already running at c:\test\loner.pl line 6.
I've used the script's full pathname as the semephore name, with backslashes switched to forward slashes as the former are disallowed. If there is the possibility of multiply named copies of the script, then use a well-known name instead.
Oh. And don't let $sem or whatever you call yours go out of scope otherwise the system semaphore gets freed. Obvious I guess, but it hung me up for a while.
|
---|