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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with die function

Status
Not open for further replies.

Lulli

Programmer
Dec 11, 2005
14
SE
Hi

I have the following script...

$cmd_add_new = 'C:/Apache2/bin/htpasswd -b logg ' . "$userid " . "$passwd";
system($cmd_add_new) or die "Update procedure failed !\n";
print "Password update successful !\n";

The last code line never executes when I run the script. This means that the system function "died" before, right? The problem is that the system function actually has done its job (because I've checked it out in the output file called "logg") and than "died" anyway ???

Thanks
 
The problem is that system calls return zero on success and non zero on failure. This means your call should be
Code:
system "$cmd_add_new" and die "Update procedure failed!\n";
It looks wrong but it's not!

Columb Healy
 
Hi

I'sorry but it didn't work. The line after die function - system ($cmd_add_new) and die "Login procedure failed !\n"; - never gets displayed even when the system function really fails.

Thanks anyway
 
Is $cmd_add_new returning success/failure to the shell (cmd)? I work on Unix rather than Wintel so I'm not sure of how to test this. It used to be on errorlevel bat that was back in the 16bit days!

If you have control of $cmd_add_new, specially if you wrote it, make sure that the exit commands return suitable values on failure.

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top