LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-30-2005, 11:54 AM   #1
tzarcone
LQ Newbie
 
Registered: Jun 2005
Posts: 1

Rep: Reputation: 0
Perl-CGI 500 Error


Hi,

I am a newbie to Linux and I am trying to get the cgi script below to run on my Linux box. I have tried to get it working on RH 9 and also Suse 9.3 both have the same error 500 internal error. I know I must be missing something I have installed CGI.PM and also file::temp but have no idea what else this cgi needs. I looked at the common things like chmod'ing it to 755 and also unpacked it from the box and copied the cgi to the cgi-bin directory.

I am able to run outher cgi and pl scripts so just think I am missing some files somewhere. When I ran perl -wc BBCorrectorServer.cgi it said something about lines 31 and also line 40. I don't think it is an error in the script because others are running it fine.

If anyone has any ideas please let me know

#!/usr/bin/perl

#
# BBCorrector Server
#
# This script accepts a block of text from the BlackBerry software
# BBCorrector, runs it through Aspell, and returns an XML packet
# indicating spelling errors.
#
# NOTES:
#
# - It is recommended you protect this script with some form of HTTP
# authentication. BBCorrector is setup to handle Basic Authentication.
#
use CGI qw(:standard Vars);
use File::Temp qw/ tempfile tempdir /;

# The Aspell executable
my $cmdAspellExe = "aspell";

# Language is US English
my $lang = "en_US";

# Options for Aspell. Puts Aspell into Ispell compatibility mode
# so that its output is written to stdout
my $cmdAspellOptions = "-a --lang=$lang";

my %FORM = Vars();

# Get the block of text from the HTTP parameter "check"
my $text2Check = "$FORM{check}";

# Convert line endings to a common format. In this case whatever
# line ending combination we get (CRLF, LF, etc), we convert to a standard
# format of LF
$text2Check =~ s/\x0D\x0A|\r/\n/g;

# Create a temporary file to store our block of text
my $dirTemp = tempdir( CLEANUP => 1 );
my( $tempHandle, $tempFilename ) = tempfile( DIR => $dir );

# Split block of text into lines and write to temp file
@lines = split( /\n/, $text2Check );
for my $line ( @lines ) {
# Force Aspell to check whole line via ^ contol character
print $tempHandle "^$line\n";
}
close $tempHandle;

# XML packet has format such as:
# <spell-results>
# <error>
# <word>maan</word>
# <position>12</position>
# <suggest>Man</suggest>
# <suggest>man</suggest>
# <suggest>moan</suggest>
# </error>
# <error>
# <word>helllo</word>
# <position>33</position>
# <suggest>hello</suggest>
# </error>
# <error>
# <word>chris</word>
# <position>41</position>
# <suggest>Chris</suggest>
# <suggest>Charis</suggest>
# </error>
# </spell-results>
my $xmlPacket = "<spell-results>";

# Do this here so that when we are debugging we can display it in return output
print header;

# Keeps track of current line number
my $lineNum = 0;

# Keeps track of the absolute position in the block of text
my $posAbsolute = 0;

# Execute Aspell
my $cmd = "$cmdAspellExe $cmdAspellOptions < $tempFilename 2>&1";
# TODO: $status most likely only tracks wether the fork failed or not, not
# whether the actual command we are running (ie: aspell) failed
my $status = open ASPELL, "$cmd |";

if ($status > 0) {
# Parse Aspell output
for my $cmdReturn (<ASPELL>) {
chomp($cmdReturn);
#print "$cmdReturn<br>\n";

if( $cmdReturn =~ /^\*/ ) {
# Line begins with *. Do nothing.

} elsif( $cmdReturn =~ /^(&|#)/ ) {
# Line begins with & or #.

# Start error element
$xmlPacket .= "<error>";

# Split return line up for easier access
my @tokens = split(" ", $cmdReturn, 5);

# Add word element which contains original misspelled word
$xmlPacket .= "<word>$tokens[1]</word>";

# Need to work out absolute position in file, not just position in current line
my $offsetIdx = 3;
if ($cmdReturn =~ /^\#/) {
$offsetIdx--;
}
my $pos = $posAbsolute + ($tokens[$offsetIdx] - 1);
$xmlPacket .= "<position>".$pos."</position>";

# Add suggestions
my @suggestions = ();
if ($tokens[4]) {
@suggestions = split(", ", $tokens[4]);
for my $suggestion (@suggestions) {
$xmlPacket .= "<suggest>$suggestion</suggest>";
}
}

# End error element
$xmlPacket .= "</error>";

} elsif( $cmdReturn =~ /^$/ ) {
# We have a blank line which indicates a line of text has been processed

my $line = $lines[$lineNum];
$posAbsolute += (length($line) + 1);
$lineNum++;
}
}
close ASPELL;

} else {
$xmlPacket .= "<exception>BBCorrector Server has encountered an error ($!)</exception>";
}

# Delete the temp file
unlink $tempFilename;

# End results XML packet
$xmlPacket .= "</spell-results>";

#print "check = $text2Check<p>\n";

# Return XML packet back to client
print "$xmlPacket\n";
 
Old 07-01-2005, 02:45 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Please post the error msgs...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RH 8.0 CGI 500 error (apache) 3Dxx Linux - General 46 06-27-2005 05:51 AM
PERL error 500 --- ronkymac Linux - Software 4 02-19-2005 07:05 AM
Apache & CGI error 500 sortia Linux - Newbie 2 01-24-2005 11:38 AM
HELP! CGI problem : HTTP 500 - Internal server error eech55 Programming 2 10-11-2004 11:27 AM
Simple Perl prog. getting Error 500 message. XxAndyxX Programming 1 07-06-2003 11:25 AM


All times are GMT -5. The time now is 12:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration