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!
Capturing return value from ExecuteCommand
Moderators: chulett, rschirm, roy
Capturing return value from ExecuteCommand
Nitin Jain | India
If everything seems to be going well, you have obviously overlooked something.
If everything seems to be going well, you have obviously overlooked something.
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.
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
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:
How to avoid this warning? Any help will be appreciated.
Thanks!
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.
If everything seems to be going well, you have obviously overlooked something.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Bingo!!!
It worked, I just appended @FM for equality check.
Ray, you are a genious. Thanks much.
It worked, I just appended @FM for equality check.
Code: Select all
Execute_Command_10.$CommandOutput = 0 : @FM
Nitin Jain | India
If everything seems to be going well, you have obviously overlooked something.
If everything seems to be going well, you have obviously overlooked something.