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

I've created a cgi script using PERL in a UNIX environment. Occassionally when the script is executed usually under the Netscape browser, I'm interrupted by the pop up message "Document Contains No Data". Unfortunately, the process is still running in the background and when the user clicks the OK button, misleading information is presented to them. It usually informs the user the process didn't run, but in fact it did, and the results page is usually blank. I'm trying to figure a way programmatically to do some spot checking in the background when this pop up message occurs, however I don't know programmatically what Netscape is sending. Is there anyone out there that may know what Netscape is sending programmatically so that when I see it I can manipulate my program to do something when the message appears. Thanks Roosevelt Jackson Systems Engineer II

Replies are listed 'Best First'.
Re: Document Contain No Data
by Abigail-II (Bishop) on Nov 05, 2002 at 20:27 UTC
    Netscape pops up this message if it sends a request, and it gets back a response without a body.

    So you will have to look at what you send, not what Netscape is sending - the popup is a response on what the server returns.

    Not that this has anything to do with Perl.

    Abigail

      Just to make explicit what is implied in Abigail's message - there is no communication between the browser and the server when the browser pops up its window -- that is, no event that you can catch and script an action for.

      Which is OK, since it will force you to fix the actual bug in your code, and not the symptom ;-)
      If you post your CGI, we can try and figure out why it's not returning any output.
Re: Document Contains No Data
by tadman (Prior) on Nov 05, 2002 at 21:18 UTC
    The only reason you get "Document contains no data." is because Netscape requested a document and the server response was zero bytes. If you look in your access_log file you will likely see a series of code 200, size 0 entries. In a standard log file, these are the two numbers following the "GET /..." text.

    What you probably want to do is debug your script, and make sure that it always returns something, even if that's an error page.

    Also, it's Perl, not PERL. Like UNIX, you could say it's case-sensitive.
Re: Document Contain No Data
by agentv (Friar) on Nov 05, 2002 at 23:14 UTC
    ...what's troubling here is that your problem occurs intermittently. Normally, if the problem is consistent, you can see what's happening by testing the program from the command-line on the server. In fact, I always recommend that you know what the program does from the command-line environment before you deploy it on your web server.

    Since this only occurs intermittently, I am guessing that under certain input conditions, your program is producing an error message or simply not creating a body of the document.

    You might consider adding code that you can use to learn what input has been supplied when the failure occurs. Then by checking your web server log for the time stamp of the failure, then look at your custom logged information for clues as to what sort of input causes your script to produce either no data, or the empty document.

    If the problem occurs frequently enough that you can trap it in a relatively short period, you might want to consider running your script in such a way that it logs its output to a file as well as sending it to STDOUT (as the Unix tee(1) command might do)

    Good luck

    ...All the world looks like -well- all the world, when your hammer is Perl.
    ---v

      POST CODE!!!!!!!!!

      Most likley you are not supplying the value of one of your variables.

      This is where good debugging techniques come in handy. Litter your script with some print "Passed 1st loop\n"; type debugging messages and see how far the program gets.

      ANYTHING that gets values from a command line script should check for value....

      $foo = `dir C:\bar\`; unless ($foo ne "") {die("Could not get directory listing\n");} @foobar = split '', $foo;

      Oh, yeah, post yer code!!!!

      And do you have warnings and Strict turned on??

      #! /usr/bin/perl -w use Strict;

      Are you using CGI.pm?? What about

      $co = new CGI; print $co->header, $co->start_html(-title=>'Retail Ad Usage');
      ~Hammy
Re: Document Contain No Data
by cLive ;-) (Prior) on Nov 06, 2002 at 09:30 UTC
    "What's troubling is blah blah (sorry, I'm not in the right place to quote :)"

    Add this to the beginning of your script:

    use CGI::Carp 'fatalsToBrowser';

    And, if you can, parse your Apache error log. (sorry, I assume you're using Apache - correct me if wrong :)

    cLive ;-)