10 Replies Latest reply on Jan 30, 2014 1:06 AM by bhaskar d

    How to Execute Perl Script with Variable Inputs

      Share This:

      Hi All,

       

      I would like to be able to take context variables in AO...pass them into a perl script... and then take the resulting outcome as a variable that can be used in my workflow. I am able to execute a perl script... I just don't know how to pass in variables and take out resulting variables into new context variables.

       

      Thanks!

       

      (If anyone has a sample, that would be awesome.)

        • 1. How to Execute Perl Script with Variable Inputs

          How do you invoke the Perl script? I do a similar thing for a Windows vbscript. I simply use a String variable and append the context item right into the script's command.Then I just take that CI as an argument when the script is exectued and I have the context item data available to the script. You need to do a little XPath-fu to strip any XML tags, though.

          • 2. Re: How to Execute Perl Script with Variable Inputs
            Umesh Sehgal

            Asha:

             

            You just need to use a script activity. Script activity in Development studio you to pass input parameter and receive output.

             

            Simple e.g.

             

            $Div=$Num1/$Num2;

             

            you will be defining Num1, Num2 as input (on input panel) and Div as output (on output panel). See screenshoht:

             

            • 3. How to Execute Perl Script with Variable Inputs

              It is not working for me. This is the script I am using (I click on View/Edit Script):

               

              #!/usr/bin/perl

               

               

              use 5.014;

               

               

              if( $strIP =~ m/^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)$/ ){

                $ strOut =("IP Address $strIP --> VALID FORMAT! \n");

                if($1 <= 255 && $2 <= 255 && $3 <= 255 && $4 <= 255){

                  $strOut=("IP address: $1.$2.$3.$4 --> All octets within range\n");

                }else{

                  $ strOut =("One of the octets is out of range. All octets must contain a number between 0 and 255 \n");

                }

              }else{

                $ strOut =("IP Address $strIP --> NOT IN VALID FORMAT! \n");

              }

               

              This is how my variables look:

              (I define strIP in an earlier Assign.)

              Development Studio_2012-02-17_12-48-04.png

               

              Yet, I get the below error when I run the job.

               

               

              ERROR - [Current Time=Fri Feb 17 12:47:32 EST 2012] [Process Name=:Sandbox01:PerlTest1] [Root Job Id=f0aa8aaa7c53def0:366eacb3:1358c6bd6fb:-80001-1329500852522] [Job Id=f0aa8aaa7c53def0:366eacb3:1358c6bd6fb:-80001-1329500852522]

              An error occurred that triggered compensation:

                Summary: Execution failed.

               

              Caused by:

                 Summary: A Value is Required for the Output Parameter: 'From' Parameter Name=strOut, 'To' Parameter Name=Output, isRequired=true, isGlobal=false.

               

               

                 

              INFO - [Current Time=Fri Feb 17 12:47:32 EST 2012] [Process Name=:Sandbox01:PerlTest1] [Root Job Id=f0aa8aaa7c53def0:366eacb3:1358c6bd6fb:-80001-1329500852522] [Job Id=f0aa8aaa7c53def0:366eacb3:1358c6bd6fb:-80001-1329500852522] 

              Stack Trace:

              procdef:Sandbox01:PerlTest1:start:execute-script[1]

               

                 

              INFO - [Current Time=Fri Feb 17 12:47:32 EST 2012] [Process Name=:Sandbox01:PerlTest1] [Root Job Id=f0aa8aaa7c53def0:366eacb3:1358c6bd6fb:-80001-1329500852522] [Job Id=f0aa8aaa7c53def0:366eacb3:1358c6bd6fb:-80001-1329500852522] 
              The process terminated in the compensated state.
              • 4. How to Execute Perl Script with Variable Inputs

                Make strOut available outside of your if/else, I usually use another var and at the end of the script use something like $strOut = $another_var; or try defining it before using it $strOut ='';

                • 5. How to Execute Perl Script with Variable Inputs

                  I alered the perl script to...Still no dice.

                   

                  #!/usr/bin/perl

                   

                   

                  use 5.014;

                   

                   

                  if($strIP =~ m/^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)$/ ){

                    $strVar =("IP Address $strIP --> VALID FORMAT! \n");

                    if($1 <= 255 && $2 <= 255 && $3 <= 255 && $4 <= 255){

                      $strVar=("IP address: $1.$2.$3.$4 --> All octets within range\n");

                    }else{

                      $strVar =("One of the octets is out of range. All octets must contain a number between 0 and 255 \n");

                    }

                  }else{

                    $strVar =("IP Address $strIP --> NOT IN VALID FORMAT! \n");

                  }

                   

                   

                  $strOut = $strVar;

                  • 6. How to Execute Perl Script with Variable Inputs

                    Did you do the modification to the Dumper.pm described in the Appendix A of the "Base Adapters User Guide" (A Using ActivePerl scripts in a Windows environment)

                    • 7. Re: How to Execute Perl Script with Variable Inputs

                      I'm getting the same error, I am running on Linux and using Perl 5.8.8 x64.

                      I have patched the Dumper.pm file as instructed, this is located in the following directory for me.

                       

                      /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Data

                       

                      Many Thanks,

                       

                      Paul.

                      • 8. Re: How to Execute Perl Script with Variable Inputs

                        i had the same issue

                        I figured its somthing wrong with my script , but couldnt find any perl output in the logs even in DEBUG mode

                        So i had to manually run the perl script on the CDP machine to figure what was wrong - a missing perl module

                         

                        So my suggestion - copy your perl and run it manually and see what you get

                        • 9. Re: How to Execute Perl Script with Variable Inputs

                          Hi,

                          I too having the problem of mapping the varibles to perl script from workflow and for numerical it is working fine but when i dealing with string variables then the problem comes.I attached the image with this and I'm using the script as follows

                           

                          in work flow the string is "Hello World..!" and is assigned to a context variable testIp and input to the perl script is testIp and the output variables as defined as follows

                          string.png

                          embedded perl script is:

                          my $var=$testIp;

                           

                          and I'm taking this var values to the out put. But when i execute the flow it is showing nothing.

                           

                          I am also facing the issue while passing the string variable which has the file path and assigned to a context variable.Now this context variable is used in the Script,but it is not working. Actually I am using a perl script file which is on the CDP and passing the file paths as input variables to that script in my workflow, but it is not working. Will anyone help me to map these kind of strings to perl script variables. Is it the problem of Script Adapter or variable mapping.

                          • 10. Re: How to Execute Perl Script with Variable Inputs

                            To the extension to my previous post.

                             

                            The problem in the previous got fixed. Actually there is no need to use the "my" to declare the variable inside the perl script. It is taking the variable whichever we name it in the output name in the String input tokens panel. No need to write the code as we do in the other editor like declare the variable using my keyword.

                                 for example if we have the variables in string input token panel like input name=Hello(string) and output name=strIp(context variable) and use this strIp variable in perl script directly like $strIp without using my key word. And same will works for Output variables also.


                            Thanks,

                            Bhaskar.