in reply to Am I missing something major here (system/exec)?

It is not immediately obvious to me under which operating system you are running, but a word of caution seems in order. On Unix systems running Apache (for example), the userid under which CGI scripts run (often 'nobody' or 'webuser') is distinct from other more privileged userids and may not have the permissions to execute your batch scripts or open certain files. Also, the environment under which a webuser runs may be quite distinct (in terms of path and other variables) from a command-line user unless you explicitly set that environment. Whenever I hear someone say "It ran fine from the command line but not from the browser" I think of these two common problem areas.

The 'print header' and fatalsToBrowser answers you have received should help you identify any further problem that you may have.


No good deed goes unpunished. -- (attributed to) Oscar Wilde
  • Comment on Re: Am I missing something major here (system/exec)?

Replies are listed 'Best First'.
Re^2: Am I missing something major here (system/exec)?
by kjg (Sexton) on May 24, 2006 at 08:31 UTC
    Thanks folks - I knew it had to be something simple, but sadly it hasn't totally sorted it.

    I'm running on a Windows NT server. Where I have the HTML and perl is the normal location for this type of stuff and other scripts there run fine (from both form and hyperlink clicking).

    I've now changed the 'runindex.pl' script to this:

    #!/usr/local/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser/; print "Content-Type:text/html\n"; print "\n"; print "<HTML>\n"; print "<Head></Head>"; print "<body>"; my $program="index.bat"; #$status= system ($program) ==0 or die "$program exited funny: $?"; print "</body>"; print "</HTML>";
    I can't 'use warnings' it's not in my Perl installation.

    I'm getting this error now

    Content-type: text/html Software error: index.bat exited funny: 256 at E:\Perlcgi\pipeline\runindex.pl line 14 +.
    and 'index.bat' isn't running (because the scripts it should run aren't updating the files they should update!).

    I can still execute 'runindex.pl' from the dos command line on the server though, so I'm dead confused.

    I've tried changing the HTML so that the script runs from a form submission, but I get exactly the same results.

    Would it be easier for me to execute the perl scripts that index.bat is trying to run, within 'runindex.pl'? (Like I know how to do that - not!) This is what index.bat does:

    todayindex.pl agentview2.pl serviceview1.pl salesview1.pl maview1.pl hoview1.pl caview1.pl bmview1.pl allindex.pl beneview1.pl charityview1.pl facview1.pl insuranceview1.pl mortview1.pl regulationview1.pl salesadvview1.pl savview1.pl systemsview1.pl trainview1.pl previndex.pl
    i.e runs a whole bunch of other perl scripts! Any more ideas? I've looked up the error code - it apparenlty can't fork the subprocesses. Why would that be?
      1. search/google for Windows && fork and you'll discover that there are some serious limitations there (and a wiser head, more familiar with NT may be able to tell you if its limitations are even more severe than those of consumer-oriented W32 OSen.

      2. Yes, of course you can execute those from your script, directly, but you may have to do so SEQUENTIALLY if your diagnosis of a fork-problem is correct. Would sequential execution be a problem?

      OTOH, I don't believe a Windows batch file does any forking. That would mean that the .bat is already trying to run your scripts sequentially, which, in turn, tends to throw the diagnosis into question.

      So, please take a look at:

      013: #$status= 014: system ($program) ==0 or die "$program exited funny: $?";

      ...and explain -- in detail -- to yourself, your teddybear and the Monks (if still need-be) what you think you're doing with those lines, noting that your script is now returning YOUR 'die' message, not something else.

      Possible HINT Did the scripts enumerated in your .bat run or not?