Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Running Perl CGIs - not working
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
The Mad Crapper
Apprentice
Apprentice


Joined: 08 Aug 2005
Posts: 156

PostPosted: Thu Nov 10, 2005 1:48 am    Post subject: Running Perl CGIs - not working Reply with quote

so i am trying to run some perl scripts that are in the my cgi-bin directory and i am getting a 500 server error. I can run sh scripts but not perl :( the 500 page tells me to look at the error log. in the error log i have
Code:
malformed header from script. Bad header=This is a test. content: perl-test
'This is a test. content' is the output of the perl script when run...

what am i missing?
Back to top
View user's profile Send private message
d11wtq
Apprentice
Apprentice


Joined: 14 Jul 2005
Posts: 192
Location: Manchester, UK

PostPosted: Thu Nov 10, 2005 2:01 am    Post subject: Reply with quote

Post the perl script please.

Also... make sure you have it chmod to allow apache to execute it.
Back to top
View user's profile Send private message
The Mad Crapper
Apprentice
Apprentice


Joined: 08 Aug 2005
Posts: 156

PostPosted: Thu Nov 10, 2005 2:12 am    Post subject: Reply with quote

i just tried to run the perl script on one of the web servers at my work that i know runs perl CGIs and i got the same thing, so the problem must be with my novice perl skills!

Code:

#!/usr/bin/perl

$foo = "content";

print "This is a test. $foo\n";


and i know the apache user can run it, the permissions are correct. (the first error i got was because of permissions)
Back to top
View user's profile Send private message
The Mad Crapper
Apprentice
Apprentice


Joined: 08 Aug 2005
Posts: 156

PostPosted: Thu Nov 10, 2005 2:50 am    Post subject: Reply with quote

anyone know why it runs on the command prompt, but not if called by apache?
Back to top
View user's profile Send private message
wjholden
l33t
l33t


Joined: 01 Mar 2004
Posts: 826
Location: Augusta, GA

PostPosted: Thu Nov 10, 2005 3:15 am    Post subject: Reply with quote

You have to tell the browser what it's reading before sending content, which means you need to send this or similar line before all other output:
Code:
Content-type: text/html\n\n
So your test script should really look like this:
Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";

$foo = "content";

print "This is a test. $foo\n";
If that doesn't work, you really do have a problem.
Actually, many people don't realise this, you can put any executable in your CGI bin, say a C program or whatever, meaning if you compile a C program and drop the binary into your CGI bin and print to stdout and read from stdin (before output, never after) it should work (example, source).
There are other mimetypes you may want to use, such as "Content-type: text/plain\n\n".
Back to top
View user's profile Send private message
The Mad Crapper
Apprentice
Apprentice


Joined: 08 Aug 2005
Posts: 156

PostPosted: Thu Nov 10, 2005 3:25 am    Post subject: Reply with quote

oh rock on man. thats it! thank you!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum