For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > March 2004 > Different responses from different systems









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Different responses from different systems
Tigerhillside

2004-03-18, 6:46 pm

I have an odd problem with my perl script. The code follows, but
here is the problem. I have a simple script, s.pl, that sends
back the time as a web page and write the calling parameters to a
file. (This will, of course, do more eventually, I just want to
make sure that some other script properly calls this script.)
When I run s.pl from the command line on my windows system it
works just fine. The html returned is correct, the correct stuff
goes into the file. I then put it on my apache server. When I run
it from the command line (perl s.pl abc=def) on that server I get
the following results in the file:

Sorry: Sat Feb 21 20:20:22 2004
page:
c_regex:
root_selected:
do: fileman
txt_input: perl s.pl abc=def
c_content:
work_path: html/cgi-bin
working_dir: /usr/home/web/users/a0017412/html/cgi-bin
c_case:
cmd_do: cmd_command
scope:


More oddly, when I call this from a browser I get the right stuff
in the file, but I get a 500 Internal Server Error returned. So
there is something odd going on, but I can't figure out what.

(BTW, I know there are easier ways to do the following, but I am
new to perl and have sort of grown and shrunk this script during
debugging.)

[begin code]

#!/usr/bin/perl -w

use CGI;

$query = new CGI;

use Time::localtime;

local *MYFILE;
my $myfilename;
$myfilename = "./a.txt";
open ( MYFILE, ">>$myfilename" ) || die("can't open datafile:
$!") ;

my $now;
$now = ctime();
print (MYFILE "\r\nSorry: $now\r\n" );

my $params;

$outQuery = new CGI;
print $query->start_html("Credit Card Problem Page");

print $outQuery->header;
print "Sorry: $now";
print $outQuery->end_html;


my %parmHash;

%parmHash = $query->Vars;


my($key, $value);
while ( ($key, $value) = each(%parmHash) )
{
if ( $key ne "session_id" ) {

print (MYFILE $key );
print (MYFILE ": " );

print (MYFILE $value );
print (MYFILE "\r\n" );
}
}

[end code]


Tigerhillside

2004-03-18, 6:46 pm

BTW, I have gone through the troubleshooting steps and those
don't help. My script "works", that is, it compiles with strict,
gives no warnings, does what it is supposed to do, but still
gives the error.

In comp.lang.perl, Tigerhillside
<Tigerhillsideremove@removenetscape.net>, I read and responded

>I have an odd problem with my perl script. The code follows, but
>here is the problem. I have a simple script, s.pl, that sends
>back the time as a web page and write the calling parameters to a
>file. (This will, of course, do more eventually, I just want to
>make sure that some other script properly calls this script.)
>When I run s.pl from the command line on my windows system it
>works just fine. The html returned is correct, the correct stuff
>goes into the file. I then put it on my apache server. When I run
>it from the command line (perl s.pl abc=def) on that server I get
>the following results in the file:
>
>Sorry: Sat Feb 21 20:20:22 2004
>page:
>c_regex:
>root_selected:
>do: fileman
>txt_input: perl s.pl abc=def
>c_content:
>work_path: html/cgi-bin
>working_dir: /usr/home/web/users/a0017412/html/cgi-bin
>c_case:
>cmd_do: cmd_command
>scope:
>
>
>More oddly, when I call this from a browser I get the right stuff
>in the file, but I get a 500 Internal Server Error returned. So
>there is something odd going on, but I can't figure out what.
>
>(BTW, I know there are easier ways to do the following, but I am
>new to perl and have sort of grown and shrunk this script during
>debugging.)
>
>[begin code]
>
>#!/usr/bin/perl -w
>
>use CGI;
>
>$query = new CGI;
>
>use Time::localtime;
>
>local *MYFILE;
>my $myfilename;
>$myfilename = "./a.txt";
>open ( MYFILE, ">>$myfilename" ) || die("can't open datafile:
>$!") ;
>
>my $now;
>$now = ctime();
>print (MYFILE "\r\nSorry: $now\r\n" );
>
>my $params;
>
>$outQuery = new CGI;
>print $query->start_html("Credit Card Problem Page");
>
>print $outQuery->header;
>print "Sorry: $now";
>print $outQuery->end_html;
>
>
>my %parmHash;
>
>%parmHash = $query->Vars;
>
>
>my($key, $value);
>while ( ($key, $value) = each(%parmHash) )
>{
> if ( $key ne "session_id" ) {
>
> print (MYFILE $key );
> print (MYFILE ": " );
>
> print (MYFILE $value );
> print (MYFILE "\r\n" );
> }
>}
>
>[end code]
>


Gunnar Hjalmarsson

2004-03-18, 6:46 pm

[ replied only to the existing group alt.perl ]

Tigerhillside wrote:
> when I call this from a browser I get the right stuff in the file,
> but I get a 500 Internal Server Error returned.


<snip>

> print $query->start_html("Credit Card Problem Page");
>
> print $outQuery->header;


You must print the header before anything else is printed to STDOUT,
so you'd better switch the order of those two lines.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Tigerhillside

2004-03-18, 6:46 pm

In alt.perl, Gunnar Hjalmarsson <noreply@gunnar.cc>, I read and
responded

>[ replied only to the existing group alt.perl ]
>
>Tigerhillside wrote:
>
><snip>
>
>
>You must print the header before anything else is printed to STDOUT,
>so you'd better switch the order of those two lines.


Thanks so much. Of course to the eye the output looked just fine.

<bangs head against wall one (hopefully) last time>


Joe Smith

2004-03-18, 6:46 pm

Tigerhillside wrote:

> #!/usr/bin/perl -w
> use CGI;


use CGI::Carp 'fatalsToBrowser'; # Avoid "500 Server Error"

> $myfilename = "./a.txt";


What directory is this file going to be created in?
Different web servers do different things.
You should use an absolute pathname, or do an
explicit chdir("/usr/home/web/users/a0017412/html").

-Joe
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com