Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flock and windows?

Status
Not open for further replies.

yim11

MIS
Jun 26, 2000
35
0
0
US
Hello,
I have a script I need to use that utilizes the flock funtion. I understand that the activestate perl install on windows does not use the flock command, my question is does anyone know a way to get around this or to allow the use of flock on a windows machine? The section of code that uses flock is posted below.

TIA for all help!

--------begin code section--------
sub read_pwd_file
{
if($pwdfile eq ""){
&send_error("503"); #failed to locate the password file
exit;
}
#open password file
unless(open(PWD,$pwdfile)){
&send_error("504"); #failed to open the password file
exit;
}
flock(PWD,$LOCK_EX);
seek(PWD,0,0);
while(<PWD>){
if (index($_,&quot;:&quot;) >= 0){
($cuser,$cpwd) = split(':',$_);
chop($cpwd);
if($users{$cuser} ne &quot;&quot;){
&send_error(&quot;Duplicate user '&quot; . $cuser . &quot;' found\n&quot;);
exit;
}
$users{$cuser}=$cpwd;
}
}
flock(CFG,$LOCK_UN);
close(CFG);

return %users;
}

<--snip-->

sub write_pwd_file
{
if($pwdfile eq &quot;&quot;){
&send_error(&quot;503&quot;); #failed to locate the password file
exit;
}
#open password file
unless(open(PWD,&quot;>&quot; . $pwdfile)){
&send_error(&quot;504&quot;); #failed to open the password file
exit;
}
flock(PWD,$LOCK_EX);
seek(PWD,0,0);
foreach $user (keys %users){
$temp = $temp . $user . &quot; :: &quot; . $users{$user} . &quot;\n&quot;;
print PWD $user . &quot;:&quot; . $users{$user} . &quot;\n&quot;;
}
flock(PWD,$LOCK_UN);
close(PWD);
}
-------end code section----------
 
flock() *does* work on WinNT - if that's any help. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top