Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Getting a return code from a perl script called via system()

by c (Hermit)
on Dec 15, 2002 at 14:34 UTC ( #220000=perlquestion: print w/replies, xml ) Need Help??

c has asked for the wisdom of the Perl Monks concerning the following question:

I think the title, sums up this one. I have a CGI script that is calling another script via system(), specifically, my $ERR = system("/usr/bin/sudo /usr/local/nbin/verify.pl --username foo --password bar"). As you can guess, the verify.pl script verifies the provided password against the system password for the spec'd username. I use Authen::PAM for the process, and in the verify.pl script, I return the result

sub check_password { ## inquiry to PAM my $pamh = new Authen::PAM($service, $username, \&my_conv_func) or die "Error code during PAM init!\n"; ## grab return from auth process. other than 0 equals failure my $answer = $pamh->pam_authenticate; return $answer; }

However, it looks as though $ERR is always set to 0 since the system call is working.

How can I get the return from my verify.pl script to show up in the value of $ERR?

thanks! -c

Replies are listed 'Best First'.
Re: Getting a return code from a perl script called via system()
by Aristotle (Chancellor) on Dec 15, 2002 at 15:13 UTC
    exit check_password @foo; and then my $exit_val = $ERR >> 8; See perldoc -f system

    Makeshifts last the longest.

Re: Getting a return code from a perl script called via system()
by FamousLongAgo (Friar) on Dec 15, 2002 at 15:19 UTC
    Why not use backticks instead of the system() call? Then you can get all the output the script generates:
    my $out = `script.pl --arg`
    Better yet, break your verification code into a module, and use it directly from the CGI script.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://220000]
Approved by vagnerr
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-06-20 22:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (96 votes). Check out past polls.

    Notices?