Operating System - OpenVMS
1751980 Members
4825 Online
108784 Solutions
New Discussion юеВ

Calling DCL from bash returns 1 on success

 
SOLVED
Go to solution
Maxy2
Advisor

Calling DCL from bash returns 1 on success

This came up as a side issue in my earlier question about running make, but since it's such a fundamental issue, I thought I'd make it its own topic.

Here is the issue. I am running GNV bash and calling some DCL commands using the DCL command. Bash captures the return value from each command that it invokes. Typically, a command that runs successfully returns an error code of 0.

It appears that successful DCL commands return 1. Example (echo $? prints the last return value):

bash$ ls makefile.mak
makefile.mak
bash$ echo $?
0
bash$ DCL dir makefile.mak

Directory DEV_SRC:[DMAX.CFTS.ELX_004_001_008_001.SRC]

MAKEFILE.MAK;2

Total of 1 file.
bash$ echo $?
1
bash$ DCL dir makefil
%DIRECT-W-NOFILES, no files found
%DIRECT-W-NOFILES, no files found
bash$ echo $?
144
bash$

This is throwing off make (and anything else that looks at return values) because it makes it appear as if every DCL command is failing because with non-zero return value.

Any general way to work around this?
4 REPLIES 4
Hoff
Honored Contributor
Solution

Re: Calling DCL from bash returns 1 on success

Mixing environments is always fun. Easiest approach? Don't mix environments. Go trigger something that does the OpenVMS parts for you, as a hunk. Trigger a make sequence that runs (entirely) in the OpenVMS context, for instance, and that returns 0 or non-zero as appropriate.

Or rebuild the DCL command in bash, if the source code is available. You'll want to map all odd values to zero here, if you take that route. Odd being success, in OpenVMS, and thus any odd value would map to zero. (I'm kinda surprised there isn't a switch on DCL to flip this. But then wildcards might not work as expected here, either.) (And the DCL command is far from the only bash command around that returns non-zero on success.)

Otherwise expect to get this stuff back here from OpenVMS. You should never get a zero status value back from an OpenVMS process.
Willem Grooters
Honored Contributor

Re: Calling DCL from bash returns 1 on success

This is normal behaviour - for DCL. ANY odd value is non-error. Even values signal a condition - warning, error or fatal. This is fundamentally different from *x where you hacve just success (0) of some other value - it could be an error or it isn't.

The environments differ so you should take that into account, and the easy way out is "don't mix". "make" is a Unix-based program so run it in bash and use "ls" (with appropiate switches). in DCL, use MMS of MMK or wahever VMS-based tool you are comfortable with.
Willem Grooters
OpenVMS Developer & System Manager
H.Becker
Honored Contributor

Re: Calling DCL from bash returns 1 on success

This is a bug in the dcl utility.

What you use as DCL (here or in your makefile) is a bash utility, essentially it is /bin/dcl. It can be used if you want to execute a dcl command from the bash.

For a bash utility it is a bug to return a VMS success status.

In your makefile you can ignore the status with the '-' prefix.

For more info on using the dcl utility you may want to read the thread 1325629
Maxy2
Advisor

Re: Calling DCL from bash returns 1 on success

Thanks everyone. Yes, using - in the makefile to ignore the return value is effective, but since I didn't totally want to ignore the return value if there is an error, I wrote this short little bash script that converts all odd return values to 0 return value.

#!/gnu/bin/bash
# Converts DCL return value into bash return code
# In DCL, odd value means success. In bash, 0 value means success.
# If DCL failure (even), return the DCL return value.
if [ $(( $1 & 1 )) -eq "1" ]
then
exit 0
else
exit $1
fi


Usage example:

bash$ DCL SHOW TIME
28-JUL-2009 09:08:29
bash$ echo Return value is $?
Return value is 1
bash$ DCL SHOW TIME ; dcl_return $?
28-JUL-2009 09:08:53
bash$ echo Return value is $?
Return value is 0
bash$ DCL DIR BLAHBLAH ; dcl_return $?
%DIRECT-W-NOFILES, no files found
%DIRECT-W-NOFILES, no files found
bash$ echo Return value is $?
Return value is 144
bash$