NewtownGuy
Technical User
Hello,
I thought I had this problem licked, but apparently not.
I'm launching a perl script from a browser but the script does not create any file output. The script passes the perl syntax check ok. I'm not getting any errors from the IE6 browser or the Apache 2 HTTP server (Listen port = 8000). I know the script is trying to run because if I try to launch a non-existant script, I get error messagea from both the browser and the HTTP server. There are no error messages with my script.
I put in a write to a test file to try to see what's happening, but nothing gets written to the file. But, at least a test file is created IF I launch the script from the command line. No test file is created when I invoke the script from the browser. I run at root. I set the script's permissions to 777.
My browser creates an invocation of the form:
Here's my script:
Can someone tell me why I'm not creating any output when I launch it from the browser ?
Can someone tell me how to pass parameters to the script when I launch it from the command line for testing ?
Thank you.
-- NewtownGuy
I thought I had this problem licked, but apparently not.
I'm launching a perl script from a browser but the script does not create any file output. The script passes the perl syntax check ok. I'm not getting any errors from the IE6 browser or the Apache 2 HTTP server (Listen port = 8000). I know the script is trying to run because if I try to launch a non-existant script, I get error messagea from both the browser and the HTTP server. There are no error messages with my script.
I put in a write to a test file to try to see what's happening, but nothing gets written to the file. But, at least a test file is created IF I launch the script from the command line. No test file is created when I invoke the script from the browser. I run at root. I set the script's permissions to 777.
My browser creates an invocation of the form:
Code:
[URL unfurl="true"]http://192.168.192.103:8000/cgi-bin/serialscript.pl?value=123456[/URL]
Here's my script:
Code:
#!/usr/bin/perl
# output a sequence of
# (a) sync -- an initial 8-bit whose value is always 0xFF,
# (b) n 8-bit values, each of which is sent to this script as two hex
# characters by caller, and
# (c) one final 8-bit value, the checksum, which is the modulo 256 sum
# of the n 8-bit values sent by caller, to a COM port
use CGI qw/:standard/;
use strict;
my $cgi = new CGI;
my $value = $cgi->param('value');
# Output of CGI Script
# - dummy no-value returned to web page to avoid error messages
print header(-status=>'204 No Content');
close (STDOUT); # Ensure nothing else gets sent.
open(TEST, ">/var/[URL unfurl="true"]www/cgi-bin/test.txt");[/URL]
print TEST $value;
close(TEST);
# Open output file and redirect to COM port
open(OUT, ">/dev/ttyS0") or "Can't open: $!";
# open(OUT, ">/var/[URL unfurl="true"]www/cgi-bin/log.txt")[/URL] or "Can't open: $!";
binmode(OUT);
flock (OUT, 2); # Lock the file to protect it from writing by others
# Output one fixed 8-bit value whose value is 0xFF
print OUT chr(hex('FF'));
# each 8-bit value to be output is sent by caller as two hex characters,
# so the number of bytes to be output (not counting the leading sync and
# trailing checksum bytes) is half the number of characters sent by
# caller
my $bytes = length($value) / 2; #each 8-bit value to be output is sent by caller as two hex characters, so the number of bytes to be output (not counting the leading sync and trailing checksum bytes) is half the number of characters sent by caller
# Initialize checksum, which will be computed as the sum of
# the $bytes (number of) 8-bit values output
my $checksum = 0;
for (my $i = 0; ($i < $bytes); $i++) {
my $hex1 = substr($value, (2 x $i), 1); #get m'th character
my $hex2 = substr($value, (2 x $i) + 1, 1); #get (m+1)'th character
my $hex1_hex2 = hex("$hex1$hex2"); #combine two hex characters into one byte from left to right
print OUT chr($hex1_hex2); #output one 8-bit value from two hex characters
my $checksum = ($checksum + $hex1_hex2) % 256; #add 8-bit value from new character to $checksum. Only compute $checksum to 8 bits since the calculation is modulo 256
}
# Output checksum as the final byte
print OUT chr($checksum);
# Unlock the file
flock(OUT, 8);
close(OUT);
Can someone tell me why I'm not creating any output when I launch it from the browser ?
Can someone tell me how to pass parameters to the script when I launch it from the command line for testing ?
Thank you.
-- NewtownGuy