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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie can't run a simple Perl script from ./first.pl

Status
Not open for further replies.

NewtownGuy

Technical User
Joined
Jul 27, 2007
Messages
146
Location
US
Hello,

I'm trying to get my first perl script running. I have two Linux test machines, and both are giving me similar errors when I access them from the command line via PuTTy from a Windows machine, and also from IE6 on the Windows machine.

The two test machines are:

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:

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

When I type this from /var/ where first.pl is located:

./first.pl

I get this:

": No such file or directory

When I type this from the same location:

perl first.pl

It runs just fine.


From Fedora Core 2, when I type:

which perl

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

When I type this into the URL line in IE6 on my PC on the same LAN as the Linux machine:


I get an Internal Server Error in IE6 and I get this from the HTTP error_log on the Fedora Core 2 machine:

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

When I type a similar line into the URL line in IE6 on my PC on the same LAN as the Linux machine, I get an Internal Server Error in IE and I get this from the HTTP error_log on the Fedora Core 3 machine:

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

I set the permission for the perl script to 777. Since the root directory for the HTTP server is /var/ and the script is in /var/ I tried using ../cgi-bin in the URL but it results in Page Not Found in IE.

I have no idea where the \r is coming from.

How do I fix these problems ?

Thank you.
 
I worked with NewTownGuy a little on this in the CGI forum and I figured someone here might have a little more insight to the problem. Where I'm at a loss is why ./first.pl fails but perl first.pl works.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[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;
 
I would say the problem is in the shebang line... when you do perl first.pl, it knows it's gonna be using Perl to run the script, whereas ./first.pl it has to read it and figure it out from there, and it might not find that Perl needs to be used.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
I think I told him to do that because for some reason some people don't have . in their profiles in unix so it's easier to just say ./file.pl


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[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;
 
did you chmod +x the script?
 
RE: did you chmod +x the script?

I used SSH Secure File Transfer to set the script's permissions to 777 to make it executable by everyone.

Is that sufficient ?

By the way, I discovered that when I used SSH Secure File Transfer to move the ASCII file from my laptop to my Linux box, that SSH Secure File Transfer chose the file transfer mode automatically, and ^M was appended to the end of each line of the script file. If it defaulted to binary transfer, I don't see why it would add characters to the file.

I've now used vi on the Linux box to edit the script file. I've removed the ^M's, and now the script runs fine from ./first.pl. Previously, it required perl first.pl to run. Apparently specifying perl gave it the ability to ignore the ^M's.

But it still won't run from just first.pl, although that may not matter.

Thank you.

 
Now that it runs from command line what happens on the web page?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[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;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top