http://qs321.pair.com?node_id=31221

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

Hello, I have a form which calls perl script "a.pl". This script does some managerial tasks and then sends a redirection back to the browser. Although, this redirection is the path to another perl script "b.pl" which produces some output to the user. The problem is that even though script "b" gets accessed (it is on a protected area so i can see the authentication box poping up) it never returns any output. Actually, the browser waits indefinetelly till i get an IO timeout. What's the correct method of redirecting from a script to another script?

Note1: I've even tried puting "b" in the same (non-protected) area as script "a" but i get the same result.
Note2: Script "b" itself (i.e. calling it directly) produces the expected output.

Note3: My server's error log:
[06/Sep/2000:12:45:53] warning (22941): for host 10.xxx.xxx.xxx trying + to GET /cgi/b.pl, start-http-response reports: write failed (Broken +p ipe) [06/Sep/2000:12:45:53] warning (22941): for host 10.xxx.xxx.xxx trying + to GET /cgi/b.pl, start-http-response reports: write failed (Broken +p ipe) [06/Sep/2000:12:48:39] failure (22941): for host 10.xxx.xxx.xxx trying + to GET /cgi/b.pl, cgieng_send_content reports: error occurred while +sending content to script (IO timeout error)
Any help really appreciated!
-n-

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Redirecting from a scipt to another script
by jreades (Friar) on Sep 06, 2000 at 18:19 UTC

    I can make a few suggestions for exploration:

    1. If you want to do this via browser redirect are you sure that the script is exiting cleanly -- this is in line with what the Anonymous Monk suggested, but I'd definitely go with trying the redirect as the last line before exit 0;.

    2. This might also be a candidate for an exec() -- rather than redirecting to the new script, launch the script 'b' from within script 'a'. There was a good thread (at least, I sure learned a lot) just a couple of weeks back. You can read it here (the thread thread picks up about midway down and I'd particularly recommend: tilly's piece and that from geeksalad.

    I also find it helpful to use the following line when debugging scripts that are on a server:

    BEGIN { $| = 1; open(STDERR, ">&STDOUT"); print "Content-Type: text/pl +ain\n\n"; }

    This nice snippet redirects STDERR to STDOUT and prints everything as text/plain to the browser -- then you can use your standard print $whatever . "\n"; while debugging.

Re: Redirecting from a scipt to another script
by Anonymous Monk on Sep 06, 2000 at 17:29 UTC
    Have you closed STDOUT and SDTERR on 'a.pl' before redirecting to 'b.pl'? The server may be waiting for those file handles to close on 'a.pl'.
Re: Redirecting from a scipt to another script
by Anonymous Monk on Jun 27, 2002 at 12:14 UTC

    The problem also occured for me on an iPlanet Web Server, while Apache had no problem with the redirect.

    I was redirecting to a relative url like: /cgi-bin/burp.pl

    Changing this to http://my.webserver.com/cgi-bin/burp.pl

    Solved it...

    Hope this helps!

    Michiel Toneman (michiel@apenstaartje.REMVE.nl)

Re: Redirecting from a scipt to another script
by mhi (Friar) on Oct 29, 2002 at 07:39 UTC
    The problem seems to have something to do with the new line of Netscape/Mozilla clients (since around Netscape 4.7).

    I have had a perl cgi application running on a Netscape Fasttrack Server 3.01 (a forerunner of the iPlanet-Servers) on HP-UX 10.20 (now 11.0) since 1998 and it never did this kind of thing with the old browsers.

    By analyzing the logs and results from debugging code I was astonished to find that everything was actually going as expected: cgi a was executed, the browser received the redirect, called cgi b, which was executed and completed. But still I kept getting core files, no output in the browser and logs of TIMEOUTS or PREMATURE EOFs as seen below until I changed from relative to absolute URLs as described by Michiel above.

    [25/Oct/2002:20:46:16] failure: for host 141.36.65.205 trying to GET / +cgi-bin/fw/fw_ordner.pl, send-cgi reports: error occurred while sendi +ng content to script (IO timeout error) [28/Oct/2002:10:49:57] failure: for host 141.36.65.205 trying to GET / +cgi-bin/fw/fw_ordner.pl, send-cgi reports: error occurred while sendi +ng content to script (premature EOF)
    This is very strange.