Scripts work from shell but not browser 
Author Message
 Scripts work from shell but not browser

I've only been writing perl scripts for a few months now. I wrote
them on one server and successfully moved them to another server
with no major hassles.

I recently moved them to a third server and now I am stumped. I
started getting Internal Server Errors. I checked all the file
permissions and paths, and the syntax checks out from the unix
shell.

I started to debug them line by line and found that they were
getting hung up on the "die" function. I experimented with
commenting out the die routine and the scripts run, but they
don't actually open, ammend, modify etc.. the files as they
should.

What is strange to me is that when I run the scripts via the unix
shell, they work perfectly. No syntax errors, and they actually
do what they are supposed to do.

The version of perl where they work is 5.005.02
The version where they don't work is 5.005, patch 03

Here is a sample of the die routine as it is written:

open (INPUT, "$data_file") || die "Can't open $data_file for
input - $!\n";

To a more experienced programmer, this may be a no-brainer, but
I'm stumped. I'm especially perplexed by the fact that it works
fine from the shell. I need them to work via a graphical browser.

Any thoughts, hints or shoves in the right direction would be
appreciated. Please let me know if you need more info.

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.*-*-*.com/



Wed, 18 Jun 1902 08:00:00 GMT  
 Scripts work from shell but not browser

on MMCDLXXXI September MCMXCIII in <URL::">
?? I've only been writing perl scripts for a few months now. I wrote
?? them on one server and successfully moved them to another server
?? with no major hassles.

On a "server"? What kind of "server"? Usually, a server is a process,
do you use some kind of "perl server", what ever that might be?

?? I recently moved them to a third server and now I am stumped. I
?? started getting Internal Server Errors. I checked all the file
?? permissions and paths, and the syntax checks out from the unix
?? shell.

Well, I guess you have a bug then. Somewhere.

However, "Internal Server Error" isn't a Perl error. All Perl errors
are in perldiag.pod. This file however has a section about "Server error".
Please read it, and pay attention to the part in bold.

?? I started to debug them line by line and found that they were
?? getting hung up on the "die" function.

How surprising. Considering that you are using die, I assume you know
what die does. But if you know what it does, you should be surprised
at all.

??                                        I experimented with
?? commenting out the die routine and the scripts run, but they
?? don't actually open, ammend, modify etc.. the files as they
?? should.

Well, and what kind of reason did Perl report? Or are you just ignoring
the return value of open, and you prefer people here guessing for the
reason - a reason you could have found in 1% of the time it took to
write your posting?

?? What is strange to me is that when I run the scripts via the unix
?? shell, they work perfectly. No syntax errors, and they actually
?? do what they are supposed to do.

Could you be a bit more vague in what you have done, and what kind
of problems you are experiencing? Now there's still a chance a set
of a million monkeys randomly typing on typewriters for a million
years might actually type the solution to your problem.

?? The version of perl where they work is 5.005.02
?? The version where they don't work is 5.005, patch 03
??
?? Here is a sample of the die routine as it is written:
??
?? open (INPUT, "$data_file") || die "Can't open $data_file for
?? input - $!\n";

And, what *was* the die message?

?? To a more experienced programmer, this may be a no-brainer, but
?? I'm stumped.

I'm stumped on why you are stumped. You open a file, and die with
a message giving the reason if the open fails. The open fails, and
you are utterly confused. You totally ignore the reason why the
open fails, and you simple remove the die. Then you are confused
it no longer dies, but still doesn't open.

??              I'm especially perplexed by the fact that it works
?? fine from the shell. I need them to work via a graphical browser.

Perl doesn't care whether it's called via a browser or not. And I highly
doubt the browser is relevant. I smell CGI, and with CGI, there is *NO*
communication between the browser and the Perl program. There's always
the middle man.

?? Any thoughts, hints or shoves in the right direction would be
?? appreciated. Please let me know if you need more info.

The groups about CGI problems are down the hall, to your left.
Just follow the smell.

Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
^V
%$^U;$^V/=$^U}while$^V!=$^W'



Wed, 18 Jun 1902 08:00:00 GMT  
 Scripts work from shell but not browser
Usually cgi scripts work in world permission. May be that is why u did not
have enough permission to open the file.
use the following two line at the top
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
You mayl get useful error message on the browser

Quote:

>I recently moved them to a third server and now I am stumped. I
>started getting Internal Server Errors. I checked all the file
>permissions and paths, and the syntax checks out from the unix
>shell.

>I started to debug them line by line and found that they were
>>What is strange to me is that when I run the scripts via the unix
>shell, they work perfectly. No syntax errors, and they actually
>do what they are supposed to do.

>The version of perl where they work is 5.005.02
>The version where they don't work is 5.005, patch 03

>Here is a sample of the die routine as it is written:

>open (INPUT, "$data_file") || die "Can't open $data_file for
>input - $!\n";



Wed, 18 Jun 1902 08:00:00 GMT  
 Scripts work from shell but not browser
I suspect that you have got a file permission problem... which has
almost nothing to do with your perl script and everything to do with how
the server is set up.

Many ISPs set up their servers to use SuExec.. this means that when an
cgi script runs in your context (i.e. from a ~username/cgi-bin  or from
a dedicated virtual domain) then the script is running as YOU, just as
if you ran it from the shell.

I would bet that on this server, they haven't set up suExec (or its
equivalents), and so the cgi script is running in the same user context
as the web server, which is often  nobody:nobody.  If this is the case,
the files you are trying to open and  read/write would have to either be
owned by nobody and be owner read/write, be in group nobody and be group
read/write, or be world read/writable.

Note: all of this is from a Unix point of view.  WindowsNT environments
have similar, but slightly different semantics.

So, check with the server administrator and see if
  a) it is apache
  b) if so, is it using suExec

-or
  c) what username / group the web server is running as

and set the file ownership / group membership and file permissions
accordingly.

Ted Marz



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. New-2-Perl: Script output to Browser not working

2. LWP and HTTPS script not working via browser/CGI calls

3. Help, shell commands not working from within script

4. runs okay in shell, not in browser

5. output in shell, but not in browser?

6. Script runs fine from shell, but browser doesn't receive variables

7. glob not working through browser

8. Perl Win32 not working with browser...

9. work on command line and not via browser?

10. Perl V4.036 on Solaris 2.3 Shell escapes do not work

11. DBI/DBD connection works in shell, not httpd

12. Works in Shell, not as cgi

 

 
Powered by phpBB® Forum Software