Solved

perl The specified CGI application misbehaved by not returning a complete set of HTTP headers.

Posted on 2013-07-01
13
593 Views
Last Modified: 2013-07-08
Hello,
I am trying to create a dynamic intranet website that will list all tif's in a folder and all its subfolders .

my code compiles fine but when I try and access via internet explorer I get the following
error
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.
my compiler is open perl ide

 
#!C:\perl\bin\perl
use strict;
use warnings;
use File::Find;
use File::Basename;
use CGI;
my $list = new CGI;
my $filedir = 'x:\0002';

print $list->header("text/html"),
print $list->start_html("Find Tif"),
$list->p("tif list");

find({ wanted => \&process_file, no_chdir => 1 },$filedir);

sub process_file {
    if (-f $_) {
        if(/\.tif$/i){
          my $cow = $_ ;
          $cow =~ s/\//\\/g; #have to get the slash's the right direction
          print $list->p(
          $list->a({-href=>$cow},
          basename($_)));
                     }
               }
}

print $list->end_html;


Thanks for any help
I have gotten other perl scripts to run fine on this server so I know that perl is installed correctly
for example this script works fine
#!c:/perl/bin/perl.exe
use strict;
use CGI; my
$list = new CGI;
my $fileDir = 'C:\Websites\info\documents';
my @files;
opendir DIR, "$fileDir" or die "Can't open $fileDir $!";
 @files = grep (/\.pdf$/,readdir(DIR));
closedir(DIR);
print       $list->header("text/html"),
      $list->start_html("Archivos in $fileDir"),
      $list->p("list of pdfs $fileDir");
 
foreach my $file (@files) {       
      print $list->p(
      $list->a({-href=>$file},
      $file)
                   );
                  }
print $list->end_html;
0
Comment
Question by:inforsystems
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39290059
The only thing I see is that your initial print seems odd (comma separators but print on 2nd line).  Try this:
print $list->header("text/html"),
    $list->start_html("Find Tif"),
    $list->p("tif list");

Open in new window


On an unrelated note.  You can make your regex more readable by using s{}{} rather than s/// so it would be:
$cow =~ s{/}{\\}g; #have to get the slash's the right direction 

Open in new window

0
 
LVL 23

Expert Comment

by:nemws1
ID: 39290176
Yeah, the 'print's are bad.  Do either wilcoxon's suggestion or separate them out (and you want a semi-colon on the end of the first line, not a comma):

print $list->header("text/html");
print $list->start_html("Find Tif");
print $list->p("tif list");

Open in new window

0
 

Author Comment

by:inforsystems
ID: 39290517
hello,

thank you for your replies

I tried both
print $list->header("text/html"),
    $list->start_html("Find Tif"),
    $list->p("tif list");

and

print $list->header("text/html");
print $list->start_html("Find Tif");
print $list->p("tif list");
 
It did not fix my issue still get the ever so helpful error message.

On the unrelated note, wow that makes it so much easier to read thanks.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39290535
Weird.  BTW - you don't need 'text/html' in your header call - it's the default:

print $list->header();

Should be good enough.  I just checked on my box and it is properly spitting out the header - no need for extra newlines after it.

Can you run this in a command shell and redirect the output to a file.  Something like this should work:

gettiflist.pl > gettif.html

And then open 'gettif.html' in *Notepad* (not a browser) and look at the first few lines.  Maybe post a screenshot of that here.


wilcoxon - I'm thinking maybe newline issue?  Been forever since I used perl on Windows outside of Cygwin - do you know if it produces just newlines or newlines and carriage returns?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39290905
This worked on Windows XP.  The links however are file system links instead of web site links so they won't open in a browser.
#!C:\perl\bin\perl
use strict;
use warnings;
use File::Find;
use File::Basename;
use CGI;
my $list = new CGI;
# my $filedir = 'x:\0002';
my $filedir = 'C:\Inetpub\wwwroot\ee';

print $list->header("text/html"),
$list->start_html("Find Jpg"),
$list->p("<b>jpg list</b>");

sub process_file {
    if (-f $_) {
        if(/\.jpg$/i){
          my $cow = $_ ;
          $cow =~ s/\//\\/g; #have to get the slash's the right direction
          print $list->p(
          $list->a({-href=>$cow},
          basename($_)));
                     }
               }
}

find({ wanted => \&process_file, no_chdir => 1 },$filedir);

print $list->end_html;

Open in new window

0
 
LVL 28

Expert Comment

by:FishMonger
ID: 39293195
Have you tried changing your shebang line to use forward slashes instead of the unescaped backslashes?

Change:
#!C:\perl\bin\perl

Open in new window

To:
#!C:/perl/bin/perl

Open in new window

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:inforsystems
ID: 39293290
Hello nemws1,

Here is the the screen shot that you wanted. looks right to me

Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Find tif</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>tif list</p><p><a href="x:\0002\Reports\10-12-00\3 lane lower copy.tif">3 lane lower copy.tif</a></p><p><a href="x:\0002\Reports\10-12-00\3 lane lower copy_11-20-00.tif">3 lane lower copy_11-20-00.tif</a></p><p><a href="x:\0002\Reports\10-12-00\3 lane lower.tif">3 lane lower.tif</a></p><p><a href="x:\0002\Reports\10-12-00\3 lane upper copy.tif">3 lane upper copy.tif</a></p><p><a href="x:\0002\Reports\10-12-00\3 lane upper copy_11-20-00.tif">3 lane upper copy_11-20-00.tif</a></p><p><a href="x:\0002\Reports\10-12-00\3 lane upper.tif">3 lane upper.tif</a></p><p><a href="x:\0002\Reports\10-12-00\4 lane lower.tif">4 lane lower.tif</a></p><p><a href="x:\0002\Reports\10-12-00\4 lane upper copy.tif">4 lane upper copy.tif</a></p><p><a href="x:\0002\Reports\10-12-00\4 lane upper.tif">4 lane upper.tif</a></p><p><a href="x:\0002\Reports\10-12-00\no track lower.tif">no track lower.tif</a></p><p><a href="x:\0002\Reports\10-12-00\no track upper.tif">no track upper.tif</a></p><p><a href="x:\0002\Reports\10-12-00\scans\3 track gym.tif">3 track gym.tif</a></p><p><a href="x:\0002\Reports\10-12-00\scans\4 track gym.tif">4 track gym.tif</a></p><p><a href="x:\0002\Reports\10-12-00\scans\first floor.tif">first floor.tif</a></p><p><a href="x:\0002\Reports\10-12-00\scans\no track gym.tif">no track gym.tif</a></p><p><a href="x:\0002\Reports\10-12-00\scans\upper gym 1.tif">upper gym 1.tif</a></p><p><a href="x:\0002\Reports\10-12-00\scans\upper gym.tif">upper gym.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Circulation.tif">Circulation.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Exisitn property.tif">Exisitn property.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Existing property.tif">Existing property.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\first flr.tif">first flr.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Future PLan A.tif">Future PLan A.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Future Plan B.tif">Future Plan B.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Property Ownership.tif">Property Ownership.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\second flr.tif">second flr.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Site A.tif">Site A.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Site Attributes.tif">Site Attributes.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Site B.tif">Site B.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Site C.tif">Site C.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\site plan.tif">site plan.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\test track.tif">test track.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Traffic.tif">Traffic.tif</a></p><p><a href="x:\0002\Reports\westfield report\drawings\Uses.tif">Uses.tif</a></p><p><a href="x:\0002\siteplan board\siteplan.tif">siteplan.tif</a></p><p><a href="x:\0002\tufts images\DSCN0001.tif">DSCN0001.tif</a></p><p><a href="x:\0002\tufts images\DSCN0002.tif">DSCN0002.tif</a></p><p><a href="x:\0002\tufts images\DSCN0003.tif">DSCN0003.tif</a></p><p><a href="x:\0002\tufts images\DSCN0004.tif">DSCN0004.tif</a></p><p><a href="x:\0002\tufts images\DSCN0005.tif">DSCN0005.tif</a></p><p><a href="x:\0002\tufts images\DSCN0006.tif">DSCN0006.tif</a></p><p><a href="x:\0002\tufts images\DSCN0007.tif">DSCN0007.tif</a></p><p><a href="x:\0002\tufts images\DSCN0008.tif">DSCN0008.tif</a></p><p><a href="x:\0002\tufts images\DSCN0009.tif">DSCN0009.tif</a></p><p><a href="x:\0002\tufts images\DSCN0010.tif">DSCN0010.tif</a></p><p><a href="x:\0002\tufts images\DSCN0011.tif">DSCN0011.tif</a></p><p><a href="x:\0002\tufts images\DSCN0012.tif">DSCN0012.tif</a></p><p><a href="x:\0002\tufts images\DSCN0013.tif">DSCN0013.tif</a></p><p><a href="x:\0002\tufts images\DSCN0014.tif">DSCN0014.tif</a></p>
</body>
</html>
0
 

Author Comment

by:inforsystems
ID: 39293309
Hello All,

I commented out the find command, and the error went away, so it looks to be either the find command itself or the sub process that is causing my issue.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39293322
Yes - that all looks correct.  So it looks like perl is running fine.

1) Have you tried turning 'strict' and 'warning' off? (remove those lines from your script).
2) Try getting a *very* simple script to work, like this, so we know that your environment is set up correctly for your web server.
#!C:\perl\bin\perl
use CGI;
my $q = new CGI;
print $q->header();
print "He<B>ll</B>o!\n";

Open in new window

0
 
LVL 23

Accepted Solution

by:
nemws1 earned 400 total points
ID: 39293343
Just saw your followup, plus re-read your original question, so my 2nd suggestion is moot. :)

Perhaps a permissions issue.  Does the user that your web server is running as have permissions to access that directory (and sub-directories)?
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39293550
Most like the problem is what nemws1 said.  Either the user the script runs as under the web server does not have permissions on the directories or the root is different for the script user under web server.
0
 

Author Comment

by:inforsystems
ID: 39294482
Hello,
I will look into the permissions, and see what I can find.
thanks
0
 

Author Comment

by:inforsystems
ID: 39307727
I changed the directory to a local directory that I knew the webserver had access to and the script worked fine.

so all I have to do is work out how to give the webserver access to the network drive.

Thanks for all your help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now