LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   FAQ: Internal Server Error / Premature End of Script Header / MS-DOS Carriage Return (https://www.linuxquestions.org/questions/red-hat-31/faq-internal-server-error-premature-end-of-script-header-ms-dos-carriage-return-310953/)

rebel 04-08-2005 12:04 AM

FAQ: Internal Server Error / Premature End of Script Header / MS-DOS Carriage Return
 
This FAQ is for people who experienced Internal Server Error on running their Perl script. Hopefully it won't be as tormenting an experience to you as it was to me.

------------------------------------------------------------

One of the most common errors in executing a Perl script is due to the CR/LF problem (i.e. existence of MS-DOS carriage returns in the script).


What happens when there is a MS-DOS carriage return in your Perl script?

INTERNAL SERVER ERROR

The server encountered an internal error or misconfiguration and was unable to complete your request.



What does the error log says? (location in redhat linux: /etc/httpd/logs/error_log )

Premature end of script header



How do I check if I have MS-DOS carriage returns in my perl script?

Go to telnet command line and use vi editor to check.

vi -b filename.pl

^M means MS-DOS carriage return

(tip: type :q! to exit vi editor)



How do I fix it?

You can add -w to #!/usr/bin/perl (i.e. #!/usr/bin/perl -w). This seems to be a temporary solution only.

The permanent solution is to delete all MS-DOS carriage returns in the script.

Donboy's suggestion: "Easiest way (for me, anyway) is to use a text editing program that allows you to change it quickly. I'm using Edit Plus from www.editplus.com. This is a text editor that is like an "advanced" notepad. You can go into the "document" pulldown and look for CR/LF and change it to Unix. it will quickly change those returns into their unix equivalent."

Another way is to write and CHMOD 777 a simple perl script to delete the carriage return (make sure you write this script without MS-DOS carriage return!).

Code:

#!/usr/bin/perl

# Usage Notes
# This script erases MS-DOS carriage return that causes errors in perl scripts
#
# Go to telnet command line
# perl nocr.pl original.txt > modified.txt
# chmod 777 modified.txt

while(<>)
{
tr/\015//d; # delete octal 15 (carriage return)
print;
}


t3gah 04-11-2005 07:30 AM

Re: FAQ: Internal Server Error / Premature End of Script Header / MS-DOS Carriage Ret
 
Quote:

Originally posted by rebel
This FAQ is for people who experienced Internal Server Error on running their Perl script. Hopefully it won't be as tormenting an experience to you as it was to me.

------------------------------------------------------------

One of the most common errors in executing a Perl script is due to the CR/LF problem (i.e. existence of MS-DOS carriage returns in the script).


What happens when there is a MS-DOS carriage return in your Perl script?

INTERNAL SERVER ERROR

The server encountered an internal error or misconfiguration and was unable to complete your request.



What does the error log says? (location in redhat linux: /etc/httpd/logs/error_log )

Premature end of script header



How do I check if I have MS-DOS carriage returns in my perl script?

Go to telnet command line and use vi editor to check.

vi -b filename.pl

^M means MS-DOS carriage return

(tip: type :q! to exit vi editor)



How do I fix it?

You can add -w to #!/usr/bin/perl (i.e. #!/usr/bin/perl -w). This seems to be a temporary solution only.

The permanent solution is to delete all MS-DOS carriage returns in the script.

Donboy's suggestion: "Easiest way (for me, anyway) is to use a text editing program that allows you to change it quickly. I'm using Edit Plus from www.editplus.com. This is a text editor that is like an "advanced" notepad. You can go into the "document" pulldown and look for CR/LF and change it to Unix. it will quickly change those returns into their unix equivalent."

Another way is to write and CHMOD 777 a simple perl script to delete the carriage return (make sure you write this script without MS-DOS carriage return!).

Code:

#!/usr/bin/perl

# Usage Notes
# This script erases MS-DOS carriage return that causes errors in perl scripts
#
# Go to telnet command line
# perl nocr.pl original.txt > modified.txt
# chmod 777 modified.txt

while(<>)
{
tr/\015//d; # delete octal 15 (carriage return)
print;
}


Good info. Thanks for posting it for the people...

You should submit this as a Tutorial here > http://www.linuxquestions.org/questions/answers.php where it won't go away because it's not a "sticky". :)

RickyRockRat 04-30-2005 03:11 PM

Use dos2unix/unix2dos :)


All times are GMT -5. The time now is 11:20 AM.