Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't open perl script "\r". No such file or directory

Status
Not open for further replies.

NewtownGuy

Technical User
Jul 27, 2007
146
US
Hello,

I'm trying to get my first cgi-script running. I have two test machines, and both are giving me similar results:

1) Linux Fedora Core 2, Apache 2.0.49 (Fedora) Server, Perl (5.8.3), HTTP listen port 8000, on 192.168.192.94 on my LAN

2) Linux Fedora Core 3, Apache 2.0.52 (Fedora) Server, Perl (5.8.5), HTTP listen port 8000, on 192.168.192.135 on my LAN

My first.pl test script is:

#!/usr/bin/perl
printf "Content-type: text/html\n\n";
printf "Hello, World";

I'm using printf because print is not supported on OS.

I type this into IE6 on the Fedora Core 2 machine:

192.168.192.94:8000/cgi-bin/first.pl

I get this:

... Can't open perl script "\r". No such file or directory
... Premature end of script headers. first.pl

When I type

which perl

I get /usr/bin/perl, which is consistent with the first line of the script.

I type a similar line into IE6 on the Fedora Core 3 machine and I get this:

... Can't open perl script "\r". No such file or directory
... Use -S to search $PATH for it
... Premature end of script headers. first.pl

When I type

which perl

I get

-bash: which: command not found

However, perl is in the same folder as for Fedora Core 2.

I set the permission for the perl script to 777. Since the root directory is supposed to be /var/ I tried using ../cgi-bin in the URL but it didn't help. I have no idea where the \r is coming from.

I found one other post, from 2005, about this exact same problem from IamStrong, but there was no answer.

How do I fix this problem ?

Thank you.
 
you need to use print not printf. It doesn't matter what the OS supports.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Thank you for the suggestion about using print not printf, but I get the exact same error message. My hunch is that I'm not getting to the point of executing the script at all.

 
I have a question about using print. I'm actually directing the character string from print out a COM port, not to the screen of the browser or to a file. Do I need the print routines installed to use such a simple print ? I have the print routines installed on the Fedora Core 3 machine, but I don't know how to configure them just to pass the characters out the COM / ttySn port. I don't have the print routines installed on the Fedora Core 2 machine.
 
Does the script work when you run it by itself? What is in the apache error log? Did you right the file on the machine or ftp it over? If FTP did you do it as ascii?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
How do I run the script by itself ? If I cd to /var/ and type first.pl, I get an error message, -bash: first.pl, command not found.

I access the HTTP server using SSH over my LAN. I created the script on a PC and moved it over using SSH Secure File Transfer. In PuTTy, using SSH, I view it with vi, and sometimes edit it directly.

For the error message, here's copy from /var/log/httpd/error_log:

[Fri Jul 27 21:12:38 2007] [error] [client 192.168.192.128] Can't open perl script "\r": No such file or directory.
[Fri Jul 27 21:12:38 2007] [error] [client 192.168.192.128] Use -S to search $PATH for it.
[Fri Jul 27 21:12:38 2007] [error] [client 192.168.192.128] Premature end of script headers: first.pl

I get the above error text when I type the URL of the script into IE.

I'm baffled as to where the \r is coming from. My client PC with IE is on 192.168.192.128.
 
Here's the text in error_log that preceeded the above error message:

[Fri Jul 27 19:30:17 2007] [notice] caught SIGTERM, shutting down
[Fri Jul 27 19:31:47 2007] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Fri Jul 27 19:31:48 2007] [notice] Digest: generating secret for digest authentication ...
[Fri Jul 27 19:31:48 2007] [notice] Digest: done
[Fri Jul 27 19:31:48 2007] [notice] LDAP: Built with OpenLDAP LDAP SDK
[Fri Jul 27 19:31:48 2007] [notice] LDAP: SSL support unavailable
[Fri Jul 27 19:31:48 2007] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Fri Jul 27 19:31:49 2007] [notice] Apache/2.0.52 (Fedora) configured -- resuming normal operations

 
Well you going to have to get the script to fun by itself before apache will attempt to run it. Try typing ./first.pl and if that fails try perl first.pl and if that fails type perl -version and post it here.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
The second method worked. Interestingly, the error message from the first method is similar to the one that I see in the error_log...

I've added a \n to the original script for the second print line.

Here are the results of the three commands you requested:

[root@001 cgi-bin]# ./first.pl
": No such file or directory.
Use -S to search $PATH for it.
[root@001 cgi-bin]# perl first.pl
Content-type: text/html

Hello, World.
[root@001 cgi-bin]# perl -version

This is perl, v5.8.5 built for i386-linux-thread-multi

Copyright 1987-2004, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at the Perl Home Page.

[root@001 cgi-bin]#
 
Can you double check that your perl location and the #! line match. ./first.pl should work if the #! is correct.

It needs to be the very first line in the script.. no blank lines above it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
How do I feed parameters (I need pairs of hex digits) to the script from the command line for testing ?

In HTML, when I call a perl script with href="cgi-bin/scriptname.pl?value=..." how do I pass pairs of hex digits to it so that I have control over every bit of the 8-bit characters that are being passed ? Is this the right path, since the root for the HTTP server is /var/ and the cgi scripts are in /var/ ?
 
You should look at the CGI module for that. I would also post in the perl forum if you need specific perl answers as that's where a lot of the perl guru's hang out.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
RE: Can you double check that your perl location and the #! line match. ./first.pl should work if the #! is correct.

It needs to be the very first line in the script.. no blank lines above it.

................

Yes, they match, and it's the first line. When I run "which perl" in Fedora Core 2, it reports exactly the way I have it in the first line of first.pl. However, in Fedora Core 3, I get an error that the "which" command doesn't exist.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top