Capturing return value from ExecuteCommand

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
koolnitz
Participant
Posts: 138
Joined: Wed Sep 07, 2005 5:39 am

Capturing return value from ExecuteCommand

Post by koolnitz »

Hi,

I have a ExecuteCommand activity with following properties set:

ExecCommand page
Command: ls
Parameters: #prmDirXml# | wc -l | tr -s ' '' ' | cut -f2 -d" "

Triggers page
Name: Link1 Expression Type:ReturnValue - (Conditional) Expression: = 0
Name: Link2 Expression Type:Otherwise Expression: N/A


Basically, I am checking in a directory for existence of file(s). Idea is to pass the flow to Link1 if no file exists, otherwise Link2.

In Director, it's showing:
waitforfile_excecutecommandactivity1..JobControl (@Execute_Command_10): Executed: ls /data/ds/hub_cmsr2/etl/xml/OI | wc -l | tr -s ' '' ' | cut -f2 -d" "
Reply=0
Output from command ====>
9


Though the output is 9, the trigger is passing the flow to Link1. It's not capturing the return value.

I also tried as below:


Triggers page
Name: Link1 Expression Type:Custom - (Conditional) Expression: Execute_Command_10.$CommandOutput = 0
Name: Link2 Expression Type:Otherwise Expression: N/A

waitforfile_excecutecommandactivity1..JobControl (@Execute_Command_10): Executed: ls /data/ds/hub_cmsr2/etl/xml/OI | wc -l | tr -s ' '' ' | cut -f2 -d" "
Reply=0
Output from command ====>
0


In this case, even if the return value is 0, it always passes the flow to Link2. It is returning the status of command execution, whereas I want to capture the output of command.


Any sugestions?

Thanks!
Nitin Jain | India

If everything seems to be going well, you have obviously overlooked something.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Early versions of DataStage have a bug where the parameter does not substitute correctly in the Execute Command. This does not appear to be your problem.

The return value is the last command executed. When you string together several commands then I would imagine that they all work succesfully so they return as a group 0. You need to execute a shell script so you can isolate the real return code.
Mamu Kim
koolnitz
Participant
Posts: 138
Joined: Wed Sep 07, 2005 5:39 am

Post by koolnitz »

Thanks Kim.

I think the ExecuteCommand is returning correct output (may be in wrong format). In the first case above, Director is displaying correct no. of files present in the directory, i.e. 9.

When I try to match $CommanOutput value with 9 or '9', it doesn't match. I tried out with Trim(), Num(), Char() and all the available functions on $CommandOutput to match, still failing.

Anyway, I tried out calling a shell script from CommandActivity. In this case, whenever it finds any file in the specified directory, it goes well. On the other hand, when it doesn't find any file, it throws a Warning, as below:

waitforfile_excecutecommandactivity2..JobControl (@Execute_Command_10): Command sh did not finish OK, reply = '1'

The script which I am calling:

Code: Select all

#!/usr/bin/ksh
#time is the session timeout period in seconds.
time=$1
echo " time= $time"
XMLFilePath=$2
echo "XML file Path is $XMLFilePath "
integer i
i=0
while [ $i != $time ]
do
   if [ -f $XMLFilePath/*.xml  ]
   then
#      echo 'File Found'
      return 0
      exit 1
   else
      sleep 1
      i=i+1
#      echo 'File Not Found'
      return 1
   fi
done

exit 0

How to avoid this warning? Any help will be appreciated.
Thanks!
Nitin Jain | India

If everything seems to be going well, you have obviously overlooked something.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

I think the exit code is what DataStage uses for return code. So exit 0 will be a return code of 0 and exit 1 is return code of 1.
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Have you tried trimming @FM as well as white space from the output? DataStage converts line termination characters into field marks.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
koolnitz
Participant
Posts: 138
Joined: Wed Sep 07, 2005 5:39 am

Post by koolnitz »

Bingo!!!

It worked, I just appended @FM for equality check.

Code: Select all

Execute_Command_10.$CommandOutput = 0 : @FM
Ray, you are a genious. Thanks much.
Nitin Jain | India

If everything seems to be going well, you have obviously overlooked something.
Post Reply