I have a perl script that now works from the windows command line (ActivePerl installed). It sends commands to turn ports on/off on a power controller (smart power strip). I have it setup so that I take a couple of command line arguments. The IP address of the device, and the power operation I want to take on that device. i.e. 10.0.40.1 on should turn the device with the IP 10.0.40.1 on, or rather turn the appropriate port on in the power controller.
I have an if elseif statement that will evaluate the IP address passed to the script and determine which power controller and what port is appropriate. The only other operation is the port and the operation are joined so if the device is on port 3 of the controller and the operation passed was 'on' then the new variable becomes 3on. This is what the remainder of the script understands and being a novice, it was easier to leave that unchanged.
THE ISSUE: When I run this command from windows either by
perl Lpower.pl 10.0.30.15 on
or
Lpower.pl 10.0.30.15 on
The issue is the point of this was to allow another application to invoke the script on my client. The other app is a piece of network management software. Through supported custom GUI extension I was able to add items to the menu for each device being managed. I have one for "Power On" and another for "Power Off". I point it to the Lpower script with the path local to my client machine, and it is invoked and runs, it also passes the arguments as expected, but my if statement does not work. It will not match on any IP, nor will it match on the operation "on" "off". I don't need to evaluate the latter, I just put a statement in their to test.
My script prints the variables, and they do show up, but the if statement doesn't work. It does not appear that it is adding leading whitespace or anything.
Here is a code snip of the relevant parts:
# $language = "PerlScript"
# $interface = "1.0"
#!c:\perl64\bin\perl -w -CA
...
print STDERR "UserUtil $version\n\n";
my ($ipaddr, $onoff) = @ARGV;
print "$ipaddr $onoff\n";
if ($onoff eq "off") {print "it matched off"}
if ($ipaddr eq "10.0.40.1") {
$epc='10.0.30.92';
$port='1';
}
elsif ($ipaddr eq "10.0.40.105") {
$epc='10.0.30.92';
$port='2';
}
elsif (($ipaddr eq "10.0.40.100") || ($ipaddr eq "10.0.40.101")) {
$epc='10.0.30.92';
$port='3';
}
...
else {print "no matches found"}
$oper="$port$onoff";
$base='http://'.$auth.'@'.$epc.'/';
print "$epc $oper $ipaddr";
cmd($oper) && die "Unknown Command $_\n";
There are some print statements in there for debugging. The output from CLI looks like this (and it works, ports power on/off as expected):
10.0.30.15 off
it matched off10.0.30.93 1off 10.0.30.15
Invoked from the web-app (which launches the script on my client)
10.0.30.15 on
Unknown Command
no matches found 10.0.30.15 off
Why would it be different? Anything I can do to force the correct handling of the arguments passed? If I read correctly they are expected to be UTF-8 encoded strings, could that app be sending something different and therefore the if statements break?
One more note. The app calls the script directly and passes the arguments, it does not call the perl executable, my environment knows what to do with a pl script. Not sure if that makes a difference.
Any Help is much appreciated. I do have some coding in my distant back-ground, but never for a profession, and completely new to perl.