search cancel

Return variable/status/value from nt/windows job - similar to sql return variables/status

book

Article ID: 254741

calendar_today

Updated On:

Products

CA Workload Automation DE - Business Agents (dSeries)

Issue/Introduction

We are trying to get the return code/value/status from a windows/nt job. Similar to sql stored procedure or other jobs listed on your docs here:

 

In this case, we're using a powershell command. Example: 

  • Command to run: powershell.exe
  • Arguments to pass: return (Get-Content "D:\path\to\data\file.txt" | Select -First 3 | Select -Last 1).Substring(12,10)

 

The output of the command can be seen in the spool - so we know it is running as expected. However, how to we get this into a variable so that they can be used by subsequent jobs? 

 

 

Environment

Release : 12.1

 

Cause

Windows and Unix jobs do not offer a way to return the STDOUT/output to a variable that can be used in subsequent jobs. 

 

Resolution

At this time there are two options (documented below). An enhancement idea/request has also been created. You can find and vote for it here: Get output variable(s)/value(s) from windows/unix jobs similar to stored procedure output variables.

 

Option 1:

Write the output of the Windows job to a network drive that the DSeries server can access via javascript. 

Con: Need to have a shared drive location to temporarily store the output data.

 

Example: 

  1. Run the Windows (or Unix) job that generates the output (and stdout output file in this case). Example:
    Command: powershell.exe
    Arguments: (Get-Content "D:\path\to\data\file.txt" | Select -First 3 | Select -Last 1).Substring(12,10) | Out-File -filepath "\\unc|nfs\path\to\output_file.txt" -Encoding utf8
  2. Then, in the next action, read using the output file of action 1 - using the following javascript:
    if (file_exist('/unc|nfs/path/to/output_file.txt'))
    {
       APPL.lineCount = file_getLineCount('/unc|nfs/path/to/output_file.txt');
    }
    if (APPL.lineCount != 0)
    {
       APPL.filedatelines = file_readLines('/unc|nfs/path/to/output_file.txt',0,1);
       APPL.filedate = APPL.filedatelines[0];
    }
  3. This makes the js variable APPL.filedate populated that can be used by subsequent jobs. 

 

Option 2:

Use the server cli to setvar to redirect output (via an environment variable) to a Global Variable. Then, use the value in the Global Variable. 

Con: The cli component would need to be installed on each agent where this needs to be done. 

Example: 

  1. Run the Unix (or Windows) job that generates the output. Example:
    Command: /bin/bash
    Arguments: -c "tail -n1 /opt/wade123/de/deserver/logs/tracelog.txt | cut -d' ' -f1-2"
    Environment Variables: Name: STDOUT, Value: /tmp/s3job

  2. Run the Unix (or Windows) job that calls the cli to use setvar. Example: 
    Command: /opt/wade123/de/deserver/bin/cli 
    Arguments: <name of your wade server> 7500 <user> <pass> 'setvar name("s3var") value("'$(cat /tmp/s3job)'")'

  3. Run the Unix (or Windows) job that uses the global variable. Example: 
    Javascript: APPL.mys3var=getVar('S3VAR','DEFAULT');
    Command: /bin/bash
    Arguments: APPL.mys3var=getVar('S3VAR','DEFAULT');