in reply to How to do system calls in cgi programs
Hi the problem will most probably be that you need the full path to your script. It should definately work if you call it like:
system( "/usr/bin/perl /full/path/to/the/script.plx" )
You are not bothering checking the return code (should be 0 if no error ) I am assuming an 0755 permissions mask (remember your CGI runs as user 'nobody' or 'apache' rather than user 'you' so it needs permissions to exec).
With your code you are using both the OO and the method call interface from CGI.pm - I have modified it to use just the method interface and have cleaned up the logic for you.
#!/usr/bin/perl -wT $|++; use strict; use CGI qw(:standard); # important shortcuts use Fcntl qw(:flock); # imports LOCK_EX, LOCK_SH, LOCK_NB my $timestamp = localtime; # this should be as suggested above "/usr/bin/perl /path/to/Kreports.p +lx" my $script_to_call = "./Kreports.plx"; $TITLE = "Kim's Report Generator"; $LOGFILE = "/usr/tmp/KreportLog"; print header,start_html($TITLE),h1($TITLE); if ( param('name') ) { # if we have a name we must have been called from our form if ( ( param('name') eq 'Kim' ) and ( param('passwrd') eq 'Knecht' + ) ) { &runReports(); } else { print "Unauthorized!\n"; } } else { # no name param so show form print hr, start_form; # hr() emits a horizontal rule: <HR> print p( $timestamp ); print p( "User ID:", textfield( -NAME => "name" ) ); print p( "Passwrd:", password_field( -NAME => "passwrd")); print p( submit( "send" ), reset( "clear" ) ); print hr; print end_form; } ##### Subs ##### sub bail { my $error = "@_"; print h1("Unexpected Error"), p($error), end_html; } sub runReports { print "Generating Reports\n"; my $exit_val = system($script_to_call); if ( $exit_val ) { print "<p>System call failed with an exit value $exit_val\n"; print "<p>Let's see what a backtic exec shows us\n"; print '<pre>', `$script_to_call`, '</pre>'; } }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to do system calls in cgi programs
by Anonymous Monk on Jan 04, 2003 at 16:53 UTC | |
|
Re: Re: How to do system calls in cgi programs
by Anonymous Monk on Jan 04, 2003 at 17:27 UTC | |
by tachyon (Chancellor) on Jan 04, 2003 at 22:48 UTC | |
by Anonymous Monk on Jan 06, 2003 at 03:50 UTC |