Professional Web Applications Themes

Running CGI through browser from local hard disk - PERL Miscellaneous

Hi folks, this probably has a simple answer ... I'm new to Perl so please be gentle. :) I am trying to test what a browser would show when accessing a CGI script, but without going through an actual server. I have Perl running fine on the local machine (Win XP) and am working through some tutorials etc. But if I try to access the file through MSIE it runs the script from a command prompt rather than piping the result back to the browser. Is this possible to do without the actual server? (I intend to put the final ...

  1. #1

    Default Running CGI through browser from local hard disk

    Hi folks, this probably has a simple answer ... I'm new to Perl so
    please be gentle. :)

    I am trying to test what a browser would show when accessing a CGI
    script, but without going through an actual server. I have Perl
    running fine on the local machine (Win XP) and am working through some
    tutorials etc. But if I try to access the file through MSIE it runs
    the script from a command prompt rather than piping the result back to
    the browser.

    Is this possible to do without the actual server? (I intend to put the
    final working script onto a real server down the track, but for
    various reasons that's not possible at this time.)

    Thanks greatly for any help.

    John Costella
    Dr. John P. Costella Guest

  2. #2

    Default Re: Running CGI through browser from local hard disk

    Dr. John P. Costella wrote:

    ....
    > I am trying to test what a browser would show when accessing a CGI
    > script, but without going through an actual server. I have Perl
    > running fine on the local machine (Win XP) and am working through some
    > tutorials etc. But if I try to access the file through MSIE it runs
    > the script from a command prompt rather than piping the result back to
    > the browser.
    >
    > Is this possible to do without the actual server? (I intend to put the
    > final working script onto a real server down the track, but for
    > various reasons that's not possible at this time.)
    ....
    > John Costella
    >
    What do you have against running a local server? Here is one in Perl if
    you don't have one:

    use HTTP::Daemon;
    use IPC::Open2;
    $|=1;
    my $server=HTTP::Daemon->new(LocalPort=>80,LocalAddr=>'localhost');
    print "Please contact me at <URL:", $server->url, ">\n";
    while($client=$server->accept){
    while(my $answer=$client->get_request){
    $ans=$answer->as_string;
    ans=split /\n/,$ans;
    $client->autoflush;
    if($answer->method eq 'GET'){
    $path=$answer->url->path;
    (error,last) unless $path=~s#^/##;
    if($path=~/html$/i){
    $client->send_file_response($path);
    last;
    }
    if($path=~/cgi$/i){
    $ENV{REQUEST_METHOD}=$answer->method;
    $query=$answer->url->query;
    $ENV{CONTENT_LENGTH}=length($query);
    $ENV{QUERY_STRING}=$query;
    $out=`perl $path`;
    $out=~s/.*?\n\n//s; #remove HTTP header
    print $client $out;
    last;
    }
    }
    if($answer->method eq 'POST'){
    $path=$answer->url->path;
    (error,last) unless $path=~s#^/##;
    if($path=~/cgi$/i){
    $query=$answer->url->query;
    $ENV{REQUEST_METHOD}=$answer->method;
    for(ans){
    $ENV{CONTENT_LENGTH}=$1 if /Content-Length: (\d+)/;
    $ENV{HTTP_REFERRER}=$1 if /Referer: (.*)/;
    }
    $query=$ans[-1];
    undef $CGI;undef $OUT;
    $pid=open2($CGI,$OUT,"perl","$path") or error;
    print $OUT $query;
    close $OUT;
    out=<$CGI>;
    waitpid $pid,0;
    $out=join "\n",out;
    $out=~s/.*?\n\n//s; #remove HTTP header
    print $client $out;
    last;
    }
    }
    last;
    }
    print "CLOSE: ", $client->reason, "\n" if $client->reason;
    undef $client;
    }

    sub error{
    $client->error(RC_FORBIDDEN);
    print "An error occurred in $ans\n";
    }

    --
    Bob Walton

    Bob Walton Guest

  3. #3

    Default Re: Running CGI through browser from local hard disk

    > I am trying to test what a browser would show when accessing a CGI
    > script, but without going through an actual server. I have Perl
    > running fine on the local machine (Win XP) and am working through some
    > tutorials etc. But if I try to access the file through MSIE it runs
    > the script from a command prompt rather than piping the result back to
    > the browser.
    >
    > Is this possible to do without the actual server? (I intend to put the
    > final working script onto a real server down the track, but for
    > various reasons that's not possible at this time.)
    Try here: [url]http://www.xarka.com/optiperl/index.html[/url] it has a trial
    download and I think it's $29 to buy. You may also do a search on
    [url]http://download.com.com[/url] I know I used to use one that had a separate
    window to show you what the CGI would look like in a Browser. (I think
    it was the OptiPerl above.

    Jeremy Fluhmann
    McLane Information Systems

    Jeremy Fluhmann Guest

  4. #4

    Default Re: Running CGI through browser from local hard disk

    "Dr. John P. Costella" wrote:
    >
    > I am trying to test what a browser would show when accessing a CGI
    > script, but without going through an actual server. I have Perl
    > running fine on the local machine (Win XP) and am working through some
    > tutorials etc. But if I try to access the file through MSIE it runs
    > the script from a command prompt rather than piping the result back to
    > the browser.
    >
    > Is this possible to do without the actual server? (I intend to put the
    > final working script onto a real server down the track, but for
    > various reasons that's not possible at this time.)
    It is a security risk to allow your browser to execute external commands
    and is the reason why good browsers (forget MSIE) do not permit such behaviour.
    Cat Guest

  5. #5

    Default Re: Running CGI through browser from local hard disk

    >> On 18 Jul 2003 13:14:39 -0800,
    >> [email]yf110vtn1.victoria.tc.ca[/email] (Malcolm Dew-Jones) said:
    > Gunnar Hjalmarsson (noreplygunnar.cc) wrote:
    > : Dr. John P. Costella wrote:
    > : > I am trying to test what a browser would show when
    > accessing a CGI : > script, but without going through an
    > actual server.
    > : Well, you do need a server.
    > Not really, though that is easiest in the long run.
    > He could simply go to the command line and run the
    > script with the desired parameters and save the output
    > in a file.
    > C:> perl my-cgi.pl submit=doit the_field=test-value > temp.htm
    > and then browse that file (temp.htm) to check what it
    > looked like.
    Yeah, but there are other considerations. The most
    obvious one is that of the userid and environment under
    which CGI programs would execute, rather than as yourself
    at the command-line.

    But I fear this is drifting way off-topic for clpm.

    hth
    t
    Tony Curtis Guest

  6. #6

    Default Re: Running CGI through browser from local hard disk

    "Malcolm Dew-Jones" <yf110vtn1.victoria.tc.ca> wrote in message
    news:3f18552fnews.victoria.tc.ca...
    > Gunnar Hjalmarsson (noreplygunnar.cc) wrote:
    > : Dr. John P. Costella wrote:
    > : > I am trying to test what a browser would show when accessing a CGI
    > : > script, but without going through an actual server.
    >
    > : Well, you do need a server.
    >
    > Not really, though that is easiest in the long run.
    >
    > He could simply go to the command line and run the script with the desired
    > parameters and save the output in a file.
    >
    > C:> perl my-cgi.pl submit=doit the_field=test-value > temp.htm
    >
    > and then browse that file (temp.htm) to check what it looked like.
    IMO, testing from the command line is something the OP should be doing
    before deployment on a CGI server.

    BTW, when you save to an HTML file, you may wish to comment out the header
    shortcut in your script, so you can open the file with your browser to see
    it as it would look in a browser, e.g.,

    #!perl -w
    # webcam_gallery.pl - command line version
    # usage - perl webcam_gallery.pl > webcam_show.htm
    use strict;
    use CGI qw(:standard);
    print
    # header,
    start_html;
    # rest of script

    Cheers.

    Bill Segraves




    William Alexander Segraves Guest

  7. #7

    Default Re: Running CGI through browser from local hard disk

    Gunnar Hjalmarsson (noreplygunnar.cc) wrote:
    : Dr. John P. Costella wrote:
    : > I am trying to test what a browser would show when accessing a CGI
    : > script, but without going through an actual server.

    : Well, you do need a server.

    Not really, though that is easiest in the long run.

    He could simply go to the command line and run the script with the desired
    parameters and save the output in a file.

    C:> perl my-cgi.pl submit=doit the_field=test-value > temp.htm

    and then browse that file (temp.htm) to check what it looked like.


    Malcolm Dew-Jones Guest

  8. #8

    Default Re: Running CGI through browser from local hard disk

    William Alexander Segraves wrote:
    > "Malcolm Dew-Jones" <yf110vtn1.victoria.tc.ca> wrote in message
    > news:3f18552fnews.victoria.tc.ca...
    >> Gunnar Hjalmarsson (noreplygunnar.cc) wrote:
    >>> Dr. John P. Costella wrote:
    >>>> I am trying to test what a browser would show when accessing
    >>>> a CGI script, but without going through an actual server.
    >>>
    >>> Well, you do need a server.
    >>
    >> Not really, though that is easiest in the long run.
    >>
    >> He could simply go to the command line and run the script with
    >> the desired parameters and save the output in a file.
    >>
    >> C:> perl my-cgi.pl submit=doit the_field=test-value > temp.htm
    >>
    >> and then browse that file (temp.htm) to check what it looked
    >> like.
    >
    > IMO, testing from the command line is something the OP should be
    > doing before deployment on a CGI server.
    Why? If you direct the exception messages to the browser, which is
    kind of natural when developing CGI scripts, personally I find 'the
    CGI way' to be more convenient.

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]

    Gunnar Hjalmarsson Guest

  9. #9

    Default Re: Running CGI through browser from local hard disk

    "Malcolm Dew-Jones" <yf110vtn1.victoria.tc.ca> wrote in message
    news:3f186200news.victoria.tc.ca...
    <snip>
    > I have never found that necessary. It's true the headers are displayed at
    > the top, but otherwise they do not interfere with the html in any way I
    > have ever noticed.
    >
    ISTM we're not talking (writing) about the same scenario. While the headers
    cause no problems when served by a CGI server; they do cause problems when
    they are at the top of an HTML file that is opened with MSIE. That's why I
    commented out the header shortcut in the example I posted for the command
    line version of a working script.

    YMMV.

    Cheers.

    Bill Segraves


    William Alexander Segraves Guest

  10. #10

    Default Re: Running CGI through browser from local hard disk

    "Gunnar Hjalmarsson" <noreplygunnar.cc> wrote in message
    news:bf9p2k$bs8pj$1ID-184292.news.uni-berlin.de...
    > William Alexander Segraves wrote:
    > > "Malcolm Dew-Jones" <yf110vtn1.victoria.tc.ca> wrote in message
    > > news:3f18552fnews.victoria.tc.ca...
    > >> Gunnar Hjalmarsson (noreplygunnar.cc) wrote:
    > >>> Dr. John P. Costella wrote:
    > >>>> I am trying to test what a browser would show when accessing
    > >>>> a CGI script, but without going through an actual server.
    <snip>
    > > IMO, testing from the command line is something the OP should be
    > > doing before deployment on a CGI server.
    >
    > Why? If you direct the exception messages to the browser, which is
    > kind of natural when developing CGI scripts, personally I find 'the
    > CGI way' to be more convenient.
    Hi, Gunnar.

    It appears to be a matter of personal preference. Personally, I prefer to do
    my syntax checking from the command line. Why would I want to run a broken
    script on a CGI server?

    In a literal sense, it appears the OP wants "without going through an actual
    server".

    Cheers.

    Bill Segraves



    William Alexander Segraves Guest

  11. #11

    Default Re: Running CGI through browser from local hard disk

    William Alexander Segraves wrote:
    > "Gunnar Hjalmarsson" <noreplygunnar.cc> wrote in message
    > news:bf9p2k$bs8pj$1ID-184292.news.uni-berlin.de...
    >> William Alexander Segraves wrote:
    >>> IMO, testing from the command line is something the OP should
    >>> be doing before deployment on a CGI server.
    >>
    >> Why? If you direct the exception messages to the browser, which
    >> is kind of natural when developing CGI scripts, personally I find
    >> 'the CGI way' to be more convenient.
    >
    > It appears to be a matter of personal preference.
    Yep. That's apparently the case. No more arguing needed, right? ;-)

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]

    Gunnar Hjalmarsson Guest

  12. #12

    Default Re: Running CGI through browser from local hard disk

    "Gunnar Hjalmarsson" <noreplygunnar.cc> wrote in message
    news:bfa7ts$cpusd$1ID-184292.news.uni-berlin.de...
    <snip>
    > > It appears to be a matter of personal preference.
    >
    > Yep. That's apparently the case. No more arguing needed, right? ;-)
    Indeed!

    All the best.

    Bill


    William Alexander Segraves Guest

  13. #13

    Default Re: Running CGI through browser from local hard disk

    William Alexander Segraves (wsegravemindspring.com) wrote:
    : "Malcolm Dew-Jones" <yf110vtn1.victoria.tc.ca> wrote in message
    : news:3f186200news.victoria.tc.ca...
    : <snip>
    : > I have never found that necessary. It's true the headers are displayed at
    : > the top, but otherwise they do not interfere with the html in any way I
    : > have ever noticed.
    : >

    : ISTM we're not talking (writing) about the same scenario. While the headers
    : cause no problems when served by a CGI server; they do cause problems when
    : they are at the top of an HTML file that is opened with MSIE. That's why I
    : commented out the header shortcut in the example I posted for the command
    : line version of a working script.

    : YMMV.

    : Cheers.

    : Bill Segraves

    Something in our setups must be different then.

    I have opened many files (i.e. local files, e.g. C:\try.htm) with MSIE of
    various versions, and have not found that mime like headers at the top of
    the file make any difference to the display, except as appearing as lines
    of text at the top of the window.

    Malcolm Dew-Jones Guest

  14. #14

    Default Re: Running CGI through browser from local hard disk

    "Malcolm Dew-Jones" <yf110vtn1.victoria.tc.ca> wrote in message
    news:3f18eb11news.victoria.tc.ca...
    <snip>
    > Something in our setups must be different then.
    >
    > I have opened many files (i.e. local files, e.g. C:\try.htm) with MSIE of
    > various versions, and have not found that mime like headers at the top of
    > the file make any difference to the display, except as appearing as lines
    > of text at the top of the window.
    >
    Well, yes. That was exactly my point. The text I did not wish to appear at
    the top of the HTML displayed in the (MSIE5.5) browser was the Content-Type
    header, e.g., for the script fragment I posted,

    Content-Type: text/html; cht=ISO-8859-1

    Note that this is not a problem in a CGI environment; but rather, is only a
    problem when generating the HTML from the command line. Indeed, the
    Content-Type header *must* be present in the CGI environment. Without it, we
    get an "Internal Server Error" message in the browser window.

    Malcolm, I think we are in agreement. As these issues are off-topic for
    clpm, we could leave the thread here (or move it to ciwac, where IMO, it
    *should* have been posted).

    Cheers.

    Bill Segraves


    William Alexander Segraves Guest

Similar Threads

  1. How to defragment my hard disk ??
    By Sara in forum Windows Server
    Replies: 1
    Last Post: June 26th, 03:04 PM
  2. What is LVD hard disk ?
    By Jose Perez in forum AIX
    Replies: 1
    Last Post: September 15th, 03:08 PM
  3. hard disk crash
    By Jose Tabisi in forum SCO
    Replies: 8
    Last Post: July 26th, 09:27 PM
  4. Installing Oracle Software on Local Disk Vs Shared Disk
    By Hari Vetsa in forum Oracle Server
    Replies: 2
    Last Post: December 13th, 10:04 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139