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

ok this is what i want to do the html pert is just to test that the script works its not of anyimportance but i will be parsing form data to the script, writing the input file tower.345 and calling up towerabc with the input file specified. i have both towerabc and a sample tower.345 files in the cgi-bin together with my perl script now this executes fine from the dos prompt but if i have a page with the action being this perl script and the submit button is clicked the html part is generated but the system() part does not run at all any suggestions
$arg="towerabc <tower.345"; system($arg); print "HTTP/1.0 200 OK\n"; print "Content-Type: text/html\n\n"; print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>Hello World</TITLE>\n"; print "</HEAD>\n"; print "<BODY>\n"; print "<H4>Hello World</H4>\n"; print "<P>\n"; print "Your IP Address is $ENV{REMOTE_ADDR}.\n"; print "<P>"; print "<H5>Have a nice day</H5>\n"; print "</BODY>\n"; print "</HTML>\n";

Replies are listed 'Best First'.
Re: Here's the script thats giving me trouble
by lhoward (Vicar) on Mar 11, 2001 at 18:33 UTC
    Two thoughts:
    1. Check your webserver error logs
    2. check the return code on your system call:
      system($arg) or die $!;
      (a "use CGI::Carp qw{fatalsToBrowser};" would help here too....)
    3. Try providing the full path to towerabc and the data file.
    and I'm not even gonna mention that putting data files and non-cgi programs in your cgi-bin directory is a bad ideatm.
      Agree on point 3: you cannot guarentee what PWD or PATH the script will be working under when you call the script via the web browser (Well, you COULD, but you shouldn't rely on this information). If you ever have to call anything external outside of perl, you should always include the full path to programs or data files.
      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      Incrementally linked image--PC correlation disabled.
      ...the rest of stuff is just the program outputs then this: execution finished - press return to terminate Content type: text/html <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD> <BODY> <H4>Hello World</H4> <P> Your IP Address is $ENV{REMOTE_ADDR}. <P><H5>Have a nice day</H5> </BODY> </HTML> command prompt here again
        I'm not sure that I understand what's going on, but you may want to print out the HTTP headers at the very beginning. It looks like maybe some other output is being sent before the header lines.

        I'm confused about "command prompt here again" at the end. Are you saying that there's a command prompt in your web page?

        buckaduck

Re: Here's the script thats giving me trouble
by sierrathedog04 (Hermit) on Mar 11, 2001 at 22:40 UTC
    When your CGI script runs online it runs as the default web user 'web' or someone similar. When you run your script from the command line and it works are you running your script as the default web user 'web'?

    If the script fails from the command line when run as the web user then that is the source of your problem. You need to grant the appropriate rights to the web user.

    Another source of the problem you describe can occur when the web user has the appropriate rights, but there is an existing tower.345 file that was created during testing by a privileged user such as root. In that case your program might fail because the web user does not have the rights to blow away a file owned by a privileged user.

    In my experience, it-runs-from-the-command-line-but-not-online CGI problems are most often caused by the default web user having insufficient rights. Give the web user sufficient rights to run the program and the problem goes away.