Re: Perl and IIS - script runs but 'The page cannot be displayed'

From: Jim Gibson (jgibson_at_mail.arc.nasa.gov)
Date: 10/27/03


Date: Mon, 27 Oct 2003 10:56:57 -0800

In article <2b68957a.0310241707.3ad7fc65@posting.google.com>, stew dean
<stewart@webslave.dircon.co.uk> wrote:
[snip]

> To get my script to work in the command line I created a new version -
> one with the variables passed to the script hard coded (although there
> are ways of doing it via the command line I've been informed) and also
> with absolute paths rather the relative ones the server doesnt mind.

Here is one suggestion: you can input the root or base directory for
your relative paths using a command-line argument. If this argument is
not present, then you can set an internal argument to a default value
such as '' (empty), '.' (default directory), or '/' (root directory),
or whatever works for your web server. This command-line argument will
not be set when executed by the web server.

When executed from a command line, the special variable @ARGV contains
the "words" entered on the command line after the script name and
separated by whitespace. You may interpret these strings anyway you
wish. CGI programs do not use this function, since the CGI data is
passed to the program by the server in environment variables. AFAIK,
command lines are never set in a CGI program (I could be wrong about
this).

Here is some code showing 3 different ways to retrieve the command line
arguments in a program:

#!/opt/perl/bin/perl -w
use strict;
use warnings;

# set a default (may be different for your server)
my $base = '/';

# only one argument, no checking
if( $#ARGV >= 0 ) {
  $base = $ARGV[0];
}

# argument entered as "-base /base/path", no checking
for my $i ( 0..$#ARGV ) {
  if( $ARGV[$i] eq "-base" ) {
    $base = $ARGV[++$i];
  }
}

# argument entered as "-base /base/path", with checking
for my $i ( 0..$#ARGV ) {
  if( $ARGV[$i] eq "-base" ) {
    if( $i < $#ARGV ) {
      $base = $ARGV[++$i];

    }else{
      die("-base option needs path argument\n");
    }
  }
}

# use the base path
print "root path is $base\n";
my $file = 'index.html';
my $fullpath = $base . $file;
print "file path is $fullpath\n";

For more information, enter "perldoc perlvar" at your friend the
command line prompt and search for "ARGV".

>
> It gave me a whole new set of errors before spitting out my HTML (all
> present and correct). These errors that I didnt see via the browser
> once fixed resulted in the end HTML being displayed when run via the
> browser.
>
> The mistakes in the perl where not syntax but warnings of wide
> characters and errors where an array memeber was called up that wasnt
> defined (like, in one example the eighth day in the week).
>
> So thanks for taking the time as your post, although not dead on
> target, did lead to me solving the problem. Now I'm looking for a way
> to avoid using the command line again (except to install modules etc)
> so I only need one script.

Using the method described above, you can modify your script to be
usable at the command line as well. I shudder at the prospect of
developing or maintaining a 20-page perl CGI script without the use of
the command line.

>
> Juding from some responces I've got (some have been downright nasty)
> this may be better in the cgi group but cheers anyway.
>
> Stew Dean



Relevant Pages