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

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

I am trying to open a new browser.
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "<INPUT type=\"button\" value=\"New Window\" onClick=\"window.op +en('test.html')\">";

test.html is in the same directory as the perl script. when the button is clicked. I get internal server error with following msg in the log

Fri Dec 3 09:04:19 2010 error (8)Exec format error: exec of /mydir/tools/cgi-bin/test.html failed.

Fri Dec 3 09:04:19 2010 error client 17.70.54.765 Premature end of script headers: /mydir/tools/cgi-bin/test.html

Thanks for your help

Replies are listed 'Best First'.
Re: Exec format error
by Utilitarian (Vicar) on Dec 03, 2010 at 08:59 UTC
    Your web server is configured to execute any files in the cgi-bin as a result when you call test.html the server attempts to execute it.

    Either change your server settings to execute on the basis of extension (.cgi or .pl) or move test.html to your htdocs directory

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
      Judging by what's in the file, it looks like test.html is meant to be executed...
        What he showed isn't test.html. "test.html is in the same directory as the perl script."
      I have updated (AddHandler) the Apache httpd.conf to execute only .pl
      <Directory "mydir/tools/cgi-bin"> AllowOverride AuthConfig Options FollowSymLinks Order allow,deny Allow from all AddHandler cgi-script .pl </Directory>
      But still getting the same error. I am new to Apache configuration ...anything else needs to be done.. Thanks again...

        Please read the error message, your target file as a .html extension. Looks like your webserver is trying to execute an html file. Read the apache documentation for more information.

        <Directory "mydir/tools/cgi-bin"> ^
        I think the directory specification here needs to be a full (absolute) path in the filesystem. See <Directory>.
        It's hard to tell without seeing the rest of the config... but maybe you also have a ScriptAlias directive set up for the directory. That would have the effect of Apache trying to execute any file in it (with the execute bit set)...

        It's probably a good idea to read up on and understand the subtle differences between ScriptAlias, option ExecCGI, SetHandler and AddHandler, and then re-check your config. Also don't forget to restart apache after having made any changes (just in case you didn't...)

        See also Dynamic Content with CGI for an overview, and Configuration Sections (for understanding which scope directives will apply to).

        If that still doesn't help, it's probably appropriate to switch to some webserver/apache forum, as the issue isn't really related to Perl at all...

Re: Exec format error
by marto (Cardinal) on Dec 03, 2010 at 09:42 UTC
Re: Exec format error
by Anonymous Monk on Dec 03, 2010 at 08:40 UTC
      Yes, the "--" on the shebang line is a nice trick to deal with potential trailing \rs.

      It isn't going to help here though, as the problem isn't that the script itself doesn't run, but rather that the webserver is also trying to execute another (non-script) file "test.html" in the same directory - which is just a webserver configuration issue.

Re: Exec format error
by roc (Sexton) on Dec 03, 2010 at 11:50 UTC

    if test.html is a pure html file the keep it under the html directory(/var/www/html)....or else try to specify the file with path.