Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- CRLF problem.
January 28, 2008, 11:19 am
rate this thread
CRLF. I upload the file to server A and it runs OK. I upload the same file
to server B and I get the 500 error message. If I chande all the CRLF to
LF the program works OK on server B.
Both servers are on Linux platforms. How can I automatically convert CRLF
to LF on server B. Or, what is server A doing that server B is not.
Re: CRLF problem.
On a Unix/Linux platform, you can remove all the CRs from a script
(or any file, really) with the following:
perl -pi.bak -e 's/\cM//g' script.pl
This removes all the CRs from the file named "script.pl", converting
all CRLFs to just LFs. (A copy of the original file will be saved as
Also, how are you uploading the file to servers A and B? If you're
using ftp, I recommend using "ascii" mode before "send"ing or
"put"ting. This will convert your Windows line endings to Unix line
endings (so that you won't have to do it yourself later).
Another thing you might try is to call the script with "perl" in
the command line, like this:
instead of just:
Not using "perl" in the command line will call whatever's specified in
the shebang line, and if the shebang line ends with a CR, like this:
the "perl^M" interpreter will be called, which can cause unexpected
things to happen.
(To confuse matters, some text editors will automatically hide the
"^M" characters, making you think they don't exist when in fact they
Calling your script with "perl" in front of it avoids several other
problems as well (like ones related to executable permissions and
$PATH issues), so I usually recommend that people run Perl scripts as
"perl script.pl" instead of just "script.pl".
So if you aren't already, call your script with "perl" before it
and see if that makes any difference.
I hope this helps, John.