extracting required string from routine return value

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
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

extracting required string from routine return value

Post by ssunda6 »

Hi,

I am executing a shell script which returns value 0 or 1 based on some conditions, using DSExecute function in a routine(transform function)

Ans=Output<1> worked fine and i got the required output.

Because of some error in the script, the script is now returning some error statements along with the return code(0/1) that I want. But I want only the last value (either 0/1) returned from the script whether it executes successfully or not.

How can I extract only the return value from the dynamic output.

Regards,
ssunda
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

Hi,

Forgot providing example of output from the script.

When we got error, the output was as follows:

tail: cannot open input
error: No such file or directory on file /opt/ofa/logs/tgt_testA.log
1


I can get the last line of output using
Ans=Output<3> . But next time if the error differs, and i have 4 lines of error, then this will not work.

Any inputs will be helpful.
Thnx,
ssunda.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If you truly don't want to see them, redirect standard error to /dev/null when you launch your script. Or use DCount to count the output and take the last one.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Ans = Field(Output, @FM, Count(Output,@FM) + 1, 1)
It appears that DCount() can not be used in this syntax.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

But Count can, it seems... yes?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

Hi Chullet, Ray

I tried both options : Count function and redirecting error messages to some file or /dev/null

Both of them are not working.
Redirecting output is not working some times. When I had an error of missing some files, it redirected all error messages except one message .

I tried using the following code in my routine :
Ans = Field(Output, @FM, Count(Output,@FM) + 1, 1)

But it is not returning anything.

Regards,
ssunda.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Because you posted in the server forum, you got answers that will work in server jobs.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

I have posted the topic in parallel forum

Regards,
ssunda.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What's parallel got to do with any of this? We are discussing a BASIC routine for goodness sake. I know you've got yourself a 'solution' but it's overly complex and it can be easily handled in other ways as mentioned here.

If you want to pursue this we can. The count and redirection do work.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

Hi,

Ans = Field(Output,@FM,Count(Output,@FM),1) is returning the required value of output.

Count(Output,@FM)+1 is giving an empty line. I think a new line is there in the output of the script.

Thanks for the replies.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There is usually a line terminator at the end of the output of each operating system command. It's this that puts the cursor on the next line when output is to screen.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ssunda6
Participant
Posts: 91
Joined: Tue Sep 19, 2006 9:32 pm

Post by ssunda6 »

ok. Thanx a lot.

Regards,
ssunda.
Post Reply