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!

Perl scripts wont run, and can't figure out why

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
My perl scripts wont run on server, but those that I download, configure, and upload work. I am running Win98 and am using the perl code editor to write/configure progs. I think the problem might be in the line endings, since the server is using unix.<br>
<br>
theEclipse<br>
robacarp.webjump.com
 
Do they run on the desktop but not the server? If so, did you give them execute authority on the server? i.e.:<br>
<br>
chmod 755 script.cgi<br>
<br>

 
One of the differences between Unix and Win/Dos is the way PATH is treated.<br>
<br>
In DOS/etc - when you type a command the shell looks first in the current directory to execute a program - and only then searches the PATH variable to find it.<br>
<br>
In Unix - the current directory is not searched when you try and run a program or script - only the $PATH variable.<br>
<br>
You can get around this in two ways:<br>
<br>
1) Keep all of the scripts/programs you want to run in a single directory - that is listed in your $PATH variable.<br>
<br>
2) When you run a script - give the full path name to it. If you're in the same directory you could type ./prog to run prog.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
What's the error message you get when you try to run the scripts on the server? This would indicate if it was a Unix problem, or a perl problem, and what the solution should be.<br>
<br>
Let us know, and we'll see what we can do :)
 
well here are the answeres:<br>
I don't know if the script would run on windows, that is I do not have a compiler for windows. maybee you can help me here too. <br>
<br>
one error message I am getting is:<br>
No such file or directory, and then it says something about checking my #! line. I did. it is correct. <br>
<br>
the other error message I am getting is:<br>
HTTP 500 - Internal server error <br>
<br>
thanks for any help you can give.<br>
robacarp.webjump.com
 
You won't need to compile anything under Windows - the Win32 port is pre-compiled and just installs pretty much as any other Win32 package. Once installed, there's a 'perl2bat' utility which will massage Unix style perl scripts into runnable batch (.bat) files, which is handy. :)<br>
<br>
Any chance you could cut & paste the actual error message into a posting? Also, if you could cut & paste the first few lines of your script as well, that might help some.<br>
<br>
The HTTP error message you get is from the web server telling you the requested script CGI failed. If you have a look in the server error logs, you'll see the errors from your script. (Might be worth also cutting & pasting these into a post as well.)<br>
<br>
thanks,<br>
Andy
 
Kay. <br>
<br>
1) where do i get this perl2bat utility, and what good does having a runnable batch file do for me.<br>
<br>
2)here is the error, cut and paste:<br>
<br>
CGI Error: Script Execution Failed<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
CGI encountered an error while attempting to execute this script: <br>
<br>
Error Message: No such file or directory <br>
Error Number: 2 <br>
This message usually indicates there is a problem with the script itself. The owner of the script needs to check the #! line for correctness. <br>
<br>
<br>
3)here is the whole script(it is not very long):<br>
<br>
#!/usr/local/bin/pearl<br>
#this is my basic starter program!!!<br>
#remember, i am just getting my feet wet!!!<br>
<br>
#this gets information from one field<br>
<br>
$fieldContents = param(&quot;myField&quot;);<br>
print &quot;Content-Type: text/html\n\n&quot;;<br>
if ($fieldContents eq &quot;010203&quot;){<br>
print(&quot;correct, you got it correct&quot;);<br>
}else{<br>
print(&quot;Wrong, hahaha&quot;);}<br>
<br>
<br>
please critique and correct this code, but when you do, please remember to tell me why it needs to be that way, so i wont forget.<br>
<br>
thanks for all your help,<br>
theEclipse<br>
robacarp.webjump.com<br>
<br>
P.S.<br>
if you want to see one of my scripts(or sort of) in action(what little they do), goto: <A HREF=" TARGET="_new"> and try either mypearl.pl, or mypearl2.pl (i know it is spelled wrong)<br>
<br>
 
perl - is the program called pearl (with an 'a'?) on your system? I haven't seen that before....<br>
<br>
think this might be the cause of your problem<br>
<br>
-ml<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Bingo! As Mike says, looks like that 'pearl' is the culprit.<br>
<br>
pl2bat is a utility you get with perl for Win32. Feed it the name of a Unix perl script you've built and copied to the Win32 machine, and it wraps it up in the necessary MS-DOS batch code to make it run. It then renames the perl script to add a &quot;.bat&quot; extension on the end so that Windows/MS-DOS will run it.<br>
<br>
HTH
 
Sounds like a solution! Hope it works out for you.<br>
<br>
I have a question. From what I know - and I'm still learning - there are two ways of getting POST data. One is via:<br>
<br>
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});<br>
<br>
You then need to parse out the variables from $buffer. The other method is to use the CGI module and call its methods. For example:<br>
<br>
use CGI;<br>
<br>
$objCGI = new CGI; # CGI Object<br>
<br>
print $objCGI-&gt;param('Phone1');<br>
<br>
<br>
The script in the last post uses "param" but it does not explicitly use the CGI module. Is CGI used as a default for this installation of perl?<br>
<br>
Any input would be appreciated.<br>

 
wow, i guess that shows what happens when you spell something wrong, and I feel really stupid for dong that, <br>
<br>
but <br>
<br>
the script still dosn't work :-(<br>
<br>
aaaaaaaahhhhhhhhhhh<br>
<br>
this time, I tried using a much simpler script, 3 lines:<br>
<br>
#!/usr/local/bin/perl<br>
print &quot;Content-Type:text/html\n\n&quot;;<br>
print &quot;The test program has run succesfully!!!&quot;;<br>
<br>
spelled perl correctly, checked the directory, everything should work just fine--but--same errors<br>
<br>
<br>
I dont have a clue what to do. <br>
<br>
<br>
and where can I get that pl2bat thingy???<br>
theEclipse<br>
robacarp.webjump.com
 
The pl2bat utility is actually known as pl2bat.bat and should be found in your Win32 perl\bin directory. For example, &quot;c:\perl\bin\pl2bat.bat&quot;.<br>
<br>
On the script not running side of things, have you got execute permissions set on the new script? If so, it may be time to look at the HTTP server. Is the CGI directory set up in the web server as being a valid CGI directory? Just a thought.
 
pl2bat.bat is for converting unix scripts to run on NT. I thought you wanted a script that will work on unix?<br>
<br>
Try these steps - from the shell prompt and in your home directory:<br>
<br>
--snip--<br>
cat &gt; atest.pl &lt;&lt;!<br>
#!/usr/local/bin/perl<br>
print &quot;hello world\n&quot;<br>
!<br>
chmod +x atest.pl<br>
./atest.pl<br>
--snip--<br>
<br>
Type everything between the --snip-- lines exactly as shown. After the last line you should see &quot;hello world&quot; printed. This will verify that perl is there.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Do what now?<br>
<br>
ok. slow down. maybee even stop. I dont currently have unix shell access. and I want scripts to run on both the webjump server and my pc. I looked and there is no pl2bat.bat file on my system, and the servers permissions are automatically set. I have also activated the cgi-bin<br>
<br>
thanks for ur help<br>
theeclipse<br>
robacarp.webjump.com
 
not sure but check the perl version, some administrators upgrade perl into diffrent folders. i.e. you may have /usr/local/bin/perl, but the admin may have installed the perl ino /usr/local/bin/perl5 or something like that. Check with the admin and if you can have someone or yourself on the web server type perl -v or perl5 -v on the command line to find out what version it is running and try whereis perl or whereis perl5<br>
<br>
This code:<br>
<br>
#!/usr/local/bin/perl<br>
<br>
### This part here is correct. I believe your problem is in the line above this one #####<br>
print &quot;Content-Type:text/html\n\n&quot;;<br>
print &quot;The test program has run succesfully!!!&quot;;<br>
<br>
also it has to be executable by everyone, so check the file permissions and make sure perl is installed and is running correctly on the server.<br>
You are on the right track!
 
thanks for all of your help<br>
<br>
I am kinda new... ok ok ok really new at this, and the scripts not working is not helping at all. I will check and see about the permissions and the perl 5 location, but I think that is the correct location. get back to ya<br>
<br>
<br>
theEclipse<br>
robacarp.webjump.com<br>

 
Well,<br>
<br>
I checked the permissions, and the location of perl. They say that their servers wont run scripts that require permissions of over 755. and the permissions are set globally, and cannot be changed on an individual basis.<br>
<br>
<br>
they have a script on the server that works just fine, and I have included it in this post, below.<br>
<br>
thanks again<br>
theEclipse<br>
robacarp.webjump.com<br>
<br>
<br>
<br>
#!/usr/local/bin/perl<br>
#print &quot;HTTP/1.0 200 OK\n&quot;;<br>
$cooky=$ENV{'HTTP_COOKIE'};<br>
$cooky=~s/(\s*)//g;<br>
@cookieArray=split(/;/, $cooky);<br>
foreach $i (@cookieArray) {<br>
($CookieArrayRowFirst, $CookieArrayRowSecond)=split(/=/, $i);<br>
$COOKIE{$CookieArrayRowFirst}=$CookieArrayRowSecond;<br>
}<br>
$COOKIE{'samcookie'}=$COOKIE{'samcookie'}+1;<br>
print &quot;Set-cookie: samcookie = $COOKIE{'samcookie'}\n&quot;;<br>
print &quot;Content-Type: text/html\n\n&quot;;<br>
<br>
print &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;New Page 2&lt;/title&gt;&quot;;<br>
print &quot;&lt;meta name=\&quot;GENERATOR\&quot; content=\&quot;Microsoft FrontPage 3.0\&quot;&gt;&quot;;<br>
print &quot;&lt;/head&gt;&lt;body&gt;&lt;p align=\&quot;center\&quot;&gt; &lt;/p&gt;\n&quot;;<br>
print &quot;&lt;p align=\&quot;center\&quot;&gt;&lt;big&gt;&lt;big&gt;&lt;font color=\&quot;#FF0000\&quot;&gt;\n&quot;;<br>
print &quot;WELCOME TO PERL!&lt;/font&gt;&lt;/big&gt;&lt;/big&gt;&lt;/p&gt;&quot;;<br>
print &quot;&lt;p&gt;&quot;;<br>
print &quot;$PATH_INFO&quot;;<br>
print &quot;&lt;/p&gt;&quot;;<br>
foreach my $envkey (%ENV)<br>
{<br>
print &quot;&lt;p&gt;$envkey&lt;/p&gt;&quot;;<br>
}<br>
<br>
read(STDIN, $poststring , $ENV{'CONTENT_LENGTH'});<br>
print &quot;$poststring&quot;;<br>
print &quot;&lt;p align=\&quot;center\&quot;&gt; &lt;/p&gt;&quot;;<br>
print &quot;&lt;div id=virtavebanner style=\&quot;visibility:hidden; position:absolute;\&quot;&gt;&quot;;<br>
print &quot;&lt;!--VirtualAvenueBanner--&gt;&quot;;<br>
print &quot;&lt;br&gt;&quot;;<br>
print &quot;&lt;br&gt;&quot;;<br>
print &quot;&lt;/div&gt;&quot;;<br>
print &quot;&lt;/body&gt;&lt;/html&gt;&quot;;<br>
__END__<br>
<br>
<br>
<br>
that is the script that works on the server, I have examined it and cut and pasted from it, and mine still dont work.
 
What happens if you run the script using perl? ie, at the command line, type:<br>
<br>
perl myscript.pl<br>
<br>
Does it work then? If it does, what permissions are set on your script? ie:<br>
<br>
ls -l myscript.pl<br>
-rwxr-xr-x 1 someuser other 3095 Feb 07 2000 myscript.pl<br>
<br>
Your permissions should look like those in the example. (rwxr-xr-x).<br>
<br>
HTH.
 
What command line? where?<br>
<br>
if you mean run the script, well it works, and outputs a whole bunch of information on the server, and perl.<br>
<br>
<br>
I am starting to think that a different server might be in order. Do you know of any that host cgi and are free (the budget is a little tight latley)or dirt cheap
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top