You're writing your script on a Windows machine, and then transferring it to a Unix/Linux machine. Right?
Because you're not transferring in ASCII mode, the line endings aren't being translated correctly, and you end up with wierd results. ...believe it or not, that's probably your problem.
Set your FTP software to ASCII mode, or use the 'dos2unix' utility to convert it after its been relocated to the runtime machine.
| [reply] |
Hi,
Yes, transfers are from Windows machine to Linux but transfer are made in ASCII mode so I don't think that's the reason.
In addition, the error log from apache says "premature end of script".
| [reply] |
Hi, Yes, you've confirmed my diagnosis: when I tested by sending a script from my Windows machine to a Linux machine in binary transfer mode (failing to convert line endings), and executed it as a CGI script, my browser told me I have an internal server error, and my apache error log told me I've had a "premature end of script" error. That's the sort of error you see, when the script terminates before the HTML header is output. I tested without the -w switch first. When I added back in the -w switch, all was ok. There is a reason for that; without the -w switch, the operating system thinks your shebang line is requesting /usr/bin/perl\r (perl\r being an invalid command name).
The point being, that my assessment of your problem is probably accurate. If you are, as you say, transferring in ascii mode, and line endings are still failing to be converted, that's an additional problem with your FTP or PSFTP software. I'd check into that. But in the meantime, get into the habbit of, immediately following your file transfer, executing "dos2unix filename.cgi" on your remote server. It's as important as remembering to set file permissions.
Humor us and try the dos2unix program to convert your line endings.
| [reply] |
Your problem might be that there is a CR after the #!/usr/bin/perl line, so
the kernel will try to use the binary named "/usr/bin/perl\r" which of course does not exist.
There's been some post about this, I'll try to search it.
Update: ah, here is it: Re: Perl Script only runs with -w switch
| [reply] |
add this to the beginning of your script also:
use CGI::Carp 'fatalsToBrowser';
That might help a bit :)
cLive ;-)
| [reply] [d/l] |