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

I am calling a script from a form thus,
<form method=POST action=http://localhost/cgi-bin/script1.cgi>
What I need to do is call anouther script at the same time.
From the same submit button would be good but the insertion of anouther line in the form
<form method=POST action=http://localhost/cgi-bin/script2.cgi>
Dosent work because it only looks at the first line.
I even tried
<form method=POST action=http://localhost/cgi-bin/script1.cgi,script2.cgi>
And even
<form method=POST action=http://localhost/cgi-bin/script1.cgi:script2.cgi>
Plus other things along that line.
Of course nothing worked.
Is there a way to call two scripts at once.
What would also work for me.
If I could put a Perl command at the end of the first script telling it as it finnishes to run the second script.

Replies are listed 'Best First'.
Re: Calling two scripts.
by Abigail-II (Bishop) on May 04, 2003 at 23:22 UTC
    Well, this isn't a Perl question. What you are trying to do doesn't work because that's not how HTML works. It wouldn't work with a CGI program written in Cobol or APL either.

    Of course, there's nothing preventing you from putting a fork as one of the first statements of your program, and do one "script" in the parent, and the other in the child.

    But that wouldn't show up as two hits in your servers log files.

    Abigail

Re: Calling two scripts.
by WhiteBird (Hermit) on May 04, 2003 at 23:51 UTC
    It depends, I'm sure, on what you need to accomplish with each script. Have you tried rolling the two scripts into one, with the second script called as a subroutine from the first script? Have you read "CGI Programming with Perl"? It has much to offer. Look at the chapter / script for the Address Book for some ideas. If you could be more specific about what you need to accomplish, there might be a more specific answer forthcoming.
Re: Calling two scripts.
by jgallagher (Pilgrim) on May 04, 2003 at 23:12 UTC
    As far as I know, this can't be done in the way you described. You could always pass it off to a third script and have it run the first two.
Re: Calling two scripts.
by Anonymous Monk on May 04, 2003 at 23:20 UTC
    Why did you try that?

    You apparently are trying your hand at CGI programming, and you don't know anything about CGI. I suggest you read about CGI before attempting to write programms using the CGI.

Re: Calling two scripts.
by Anonymous Monk on May 04, 2003 at 23:32 UTC
    <!-- Name as script0.cgi --> <html> <body> <H1>Please click both buttons below in quick succession. (Thanks.)</ +H1> <form method=POST action=http://localhost/cgi-bin/script1.cgi> <button type=SUBMIT /> </form> <form method=POST action=http://localhost/cgi-bin/script2.cgi> <button type=SUBMIT /> </form> </body> </html>
      Uh, I don't think that will work. The browser might send both requests, but only data from one will be returned. Besides the technical problems, you really don't want to require your users to click two buttons in rapid succession.

        :)

      Dear Anonymous Monk,
      You have restored my belife, that all programers have a unique sense of humour.
      Thank you all for everything in the past.
      I actually pulled the counter script apart and inserted the following on the end of Script1.
      $filename = 'hits.data'; $main_dir = 'C:/Apache2/cgi-bin/sample'; $autoadd=1; $view_log='***********'; &FormInput(*input); $addnew=0; $lock = "$main_dir/count_lock.lock"; if ($input{'view'} ne $view_log) { &SetLock; } open(DATA,"$main_dir/$filename"); @lines = <DATA>; close(DATA); if ($input{'view'} eq $view_log) { } else { open(DATA,">$main_dir/$filename"); foreach $line (@lines) { ($link_url, $link_count1) = split(/\|/,$line); if ($input{'url'} eq $link_url1) { $link_count1++; print DATA ("From the Sample script.|$link_count1\n"); $addnew=1; } else { print DATA $line; } } if ($addnew == 0 && $autoadd == 1) { print DATA ("$input{'url'}|1\n"); } &EndLock; close(DATA); if ($input{'url'} !~ m?://?) { $input{'url'} = "http://" . $input{'url'}; } } exit; sub FormInput { local (*qs) = @_ if @_; if ($ENV{'REQUEST_METHOD'} eq "GET") { $qs = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$qs,$ENV{'CONTENT_LENGTH'}); } @qs = split(/&/,$qs); foreach $i (0 .. $#qs) { $qs[$i] =~ s/\+/ /g; $qs[$i] =~ s/%(..)/pack("c",hex($1))/ge; ($name,$value) = split(/=/,$qs[$i],2); if($qs{$name} ne "") { $qs{$name} = "$qs{$name}:$value"; } else { $qs{$name} = $value; } } return 1; } sub SetLock { $timecheck = 0; while(-e $lock) { sleep(5); $timecheck = $timecheck + 1; if ($timecheck >= 5) { unlink("$lock"); } } open(LOCKFILE,">$lock"); close(LOCKFILE); return; } sub EndLock { unlink("$lock"); return; }

      there would be much more left there than I really need .
      But it workes wonderfully fine .
      So I am happy.
      Nasa.