When you call the other cgi, are you trying to get data? Where does the other cgi exist? On another machine? In the same directory? What are you trying to do by calling it?

Your meta tag tells the browser to go to the next script. If your initial cgi say, takes a form submission, massages/corrects the data and then redirects to the next page that should be fine. If, instead you want it to take the form submission, massage or correct/validate the data and then call another script if it's good or the previous script if it's bad there might be better options.

Of course, you've probably realised now that you haven't given us enough information.

Here might be some answers to your question, note that in each I only call one script. It shouldn't be too hard for you to throw conditionals around stuff if that's what you need to do:

#!/usr/bin/perl -wT # don't forget -T for cgi scripts ##### First some setup use CGI; use strict; my $cgi = CGI->new; # some sort of processing on incomming arguments my %args; foreach my $arg (qw/surname firstname dob pet_name/) { my $tainted = $cgi->param($arg) || ""; ($args{$arg}) = ($tainted =~ m!([\w _/.-]+)!; # pick your sa +fe # input charac +ters } print $cgi->header; ##### Now some options/interpretations #### # a) call fish.cgi with these results and display it's output. # this script may be on another server: { use LWP::UserAgent; $SIG{ALRM} = sub {die "LWP request timed out."}; my $url = "http://www.somewhere.com.au/fish.cgi"; # add any query string you want here ie: my $clean_surname = $cgi->escape($args{surname}); $url .= "?surname=$clean_surname"; # Create a user agent object my $ua = new LWP::UserAgent; # create the request object (POST or GET) my $req = new HTTP::Request ("POST" => $url); # Set the POSTed input (if necessary) # I'm certain there's a better way to do this. my $input; foreach my $value (keys(%args)) { my $clean_value = $cgi->escape($args{$value}); $input .= "$value=$clean_value\n"; } # Set the content type if necessary $req->content_type('application/x-www-form-urlencoded'); # Give the request object the POSTed input $req->content($input); my $content; eval { alarm(60); # time out after 1 minute # Pass request to the user agent and get a response ba +ck my ($code, $msg, $headers); my $res = new HTTP::Response ($code, $msg, $headers, $ +content); $res = $ua->request($req); # Get our content $content = $res->content(); ### Finished call to the other script, so cancel the a +larm alarm(0); }; # Check for error if($@ =~ /timed out/) { die $@; } # else do something with $content print $content; } #### # b) Call a script from some directory directly (without LWP) # and grab the results { my $otherscript = "/some/directory/somewhere/script.pl"; # pretend we're using CGI in this script and that # we've set it up (different for different versions) t +o # be okay with stuff like: surname=foo etc my $input; $input = "surname=$args{surname} firstname=$args{firstname}"; # etc, the foreach above is better than this of course +. # if you want results here to be an array of lines, # where the first element of the array is the first li +ne # returned and the second is the second line returned +etc # s/\$results/@results/ and it'll behave that way my $results = qx/$otherscript $input/; # do something with our results: print $results; } #### # c) Call another script from some directory directly # and have it take over things from here: { my $otherscript = "/some/directory/somewhere/script.pl"; my $input; $input = "surname=$args{surname} firstname=$args{firstname}"; exec($otherscript, $input); # the end, this script won't come back from here. }
The blocks around each option are more for visual distinction and are not strictly necessary (except for the fact that I do my $otherscript twice etc.

If you go with the first idea I also suggest moving the use LWP::UserAgent; to the top of your script up near use strict; because it'll make more sense to your scripts maintainer.

If you have any questions about these answers feel free to ask. If you want to have another go at trying to ask your question that might be a good idea too. ;) You can most easily do this by replying to your original post here with the answers the the questions we've asked you.

Hope it helps.

jarich


In reply to Re: Calling a cgi with another cgi by jarich
in thread Calling a cgi with another cgi by Donnie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.