RobKelley

Call a Perl script from Lua

Discussion created by RobKelley on Dec 21, 2011
Latest reply on Jan 5, 2012 by Jarrod

Special thanks to Matt Ritter of YJT Solutions for his significant contributions to the Lua code.

 

I'm more comfortable coding in Perl and was looking for a way to call a Perl script from Lua and then do most of the heavy lifting with Perl.  The Lua script below is called by an AO rule that runs on alarm arrival, gets the event message and passes it to a Perl script as a parameter.  The Perl script consumes the parameter and writes it to a file simply to prove-out the concept.

 

I now need to update both scripts so that the a result can be returned to the same Lua script for processing.  Any help in this area would be most appreciated.

 

Lua script

-- --           Name: LuaPasses2Perl --         Author: Rob Kelley --   Date Created: December 19 2011 --        Purpose: Passes a parameter to a Perl script for execution --Important Notes: 1> This script can On message arrival (on_arrival) action mode. --                 2> Perl must be sourced in order to run this script unless --                    the Perl script is called from the Perl home directory. --  -- Get the AO filtered alarm al=alarm.get()  -- Write the Alarm message to a variable alarmMSG = al[1].message  -- Pass the Alarm message to a Perl script output,i = action.command('d:\\ESM\\bin\\LuaPasser.pl ' .. alarmMSG)

 

 Perl script

#!d:\\perl64\\bin\\perl  ###################################################################### #           Name: LuaPasser.pl                                                    #         Author: Rob Kelley                                                      #   Date Created: December 19 2011                                                #        Purpose: Receives a parameter from a Lua script and writes it to a file  #                 in order to prove-out that a perl script can be called from Lua #Important Notes: This script is called by LuaPasses2Perl script                  ##################################################################################  $out = ">d:\\ESM\\logs\\LuaParser.out"; $param1 = @ARGV[0]; open OUT, $out or die "Unable to open log file.  Exiting script. [$!]"; #print OUT "@ARGV[0]\n"; print OUT "$param1\n"; close OUT;

Outcomes