Operating System - OpenVMS
1753288 Members
5765 Online
108792 Solutions
New Discussion юеВ

Re: Could command search return a status of 1 if nomatch

 
SOLVED
Go to solution

Could command search return a status of 1 if nomatch

I have a backup script that generate error messages all the time. I found that the search command will always return a status of 1 even if no matches. Could you point out what's wrong with it.

$ search 'log_file' "-w-", "-acconflict" /match=xor /out='tmp_file'1
$ sh sym $status
$ if $status .eq. 1
$ then
$ search 'tmp_file'1 "-w-", "-nosuchfile" /match=xor /out='tmp_file'2


$ search SOS_BACKUP_LOG:ALPHASYS-2508.LIS "-w-", "-acconflict" /match=xor /out=
SOS_BACKUP_LOG:BACKUP.TMP1
%SEARCH-I-NOMATCHES, no strings matched
$ sh sym $status
$STATUS = "%X00000001"
$ if $status .eq. 1
$ then
$ search SOS_BACKUP_LOG:BACKUP.TMP1 "-w-", "-nosuchfile" /match=xor /out=SOS_
BACKUP_LOG:BACKUP.TMP2
%SEARCH-I-NULLFILE, file DISK1:[SOS_BACKUP.LOG]BACKUP.TMP1;1 contains no records
%SEARCH-I-NOMATCHES, no strings matched
$
8 REPLIES 8
John McL
Trusted Contributor

Re: Could command search return a status of 1 if nomatch

If you use the command $ SHOW SYMBOL $STATUS you'll find that it's a string, as is $SEVERITY.

Re: Could command search return a status of 1 if nomatch

thanks for the reply.

it doesn't matter if it is a string or integer. DCL will try to convert the symbol to integer first.

My question is if nomatches occurs during search. The exit status should not be "%X00000001" but "%X08D78053".
John McL
Trusted Contributor
Solution

Re: Could command search return a status of 1 if nomatch

Your output has the lines
$ sh sym $status
$STATUS = "%X00000001"

When I do it from a command procedure I get
$STATUS == "%X08D78053"

Note the == compared to your =. Are you accessing a local symbol $STATUS rather than the global symbol.
P Muralidhar Kini
Honored Contributor

Re: Could command search return a status of 1 if nomatch

Hi Richard,

The program output that you have provided is strange.

I tried a similar program and was got $STATUS as "%X08D78053".
I tried this on V84 Integrity.

Which OpenVMS version are you using ?

Regards,
Murali
Let There Be Rock - AC/DC

Re: Could command search return a status of 1 if nomatch

Thanks for all the replys.

John,
You found the problem.


There is a local assignment in the calling procedure.

$STATUS = F$TRNLNM("ERROR_STAT")

I will fix that.

Thanks again.
Hein van den Heuvel
Honored Contributor

Re: Could command search return a status of 1 if nomatch

What we are all trying to say here is that someone picked a really bad symbol name to copy $status into. Remember that thing about $ symbols being reserved? This is why!

The LOCAL symbol $status presumably with some old status value is hiding/masking/whatever-you-want-to-call-it the global symbol $status which holds the current status.

Try this:

$ tmp.com
$ create tmp.tmp
$ $status = $status
$ show symb/glo $status
$ show symb/loc $status
$ sear tmp.tmp blah
$ show symb/glo $status
$ show symb/loc $status
$ exit

$ @tmp

hth,
Hein


Re: Could command search return a status of 1 if nomatch

Thanks guys. I am happy now.
John Gillings
Honored Contributor

Re: Could command search return a status of 1 if nomatch

Richard,

There are some other issues in the code you posted...

Ignoring any overloading of the symbol name "$status", let's look at this snippet:

>$ search 'log_file' "-w-", "-acconflict" /match=xor /out='tmp_file'1
>$ sh sym $status
>$ if $status .eq. 1

You should think of $STATUS and $SEVERITY being set at the end of *any* command, thus your code risks testing the status of the SHOW SYMBOL command, rather than of the SEARCH command.

As it happens, a *successful* SHOW SYMBOL command does not change $STATUS, but that's an inconsistency in DCL, most likely intended to make sequences like yours work.

However, the general case is $STATUS is changed after every command. If, for example, you wrote:

$ search 'log_file' "-w-", "-acconflict" /match=xor /out='tmp_file'1
$ WRITE SYS$OUTPUT "SEARCH status=",$status
$ IF $STATUS.EQ. 1

you would be testing $STATUS from the WRITE command.

You're much safer copying the $STATUS from the command of interest into a local variable:

$ search 'log_file' "-w-", "-acconflict" /match=xor /out='tmp_file'1
$ stat=$status
$ SHOW SYM stat
$ IF stat.EQ. 1

Another issue.

In testing OpenVMS status values (better described as OpenVMS Condition Codes), it's never a good idea to do a direct comparison. That's because $STATUS is really a record of bit fields, parts of which may or may not be set without affecting the meaning of the value. See the OpenVMS Programming Concepts manual for detail about how condition codes are formed and how to correctly interpret them.

For some purposes it's better to look at $SEVERITY than $STATUS. It will tell you if the result is Warning, Success, Error, Informational or Fatal. If you need more detail, you should mask off the field of interest. Here are the (hex) masks for the bit fields:

STS$M_SUCCESS =%X1
STS$M_SEVERITY =%X7
STS$M_MSG_NO =%XFFF8
STS$M_CODE =%X7FF8
STS$M_FAC_SP =%X8000
STS$M_FAC_NO =%XFFF0000
STS$M_COND_ID =%XFFFFFF8
STS$M_CONTROL =%XF0000000
STS$M_CUST_DEF =%X8000000
STS$M_INHIB_MSG =%X10000000

AND the mask with $STATUS to test that field. For example:

$ IF stat.AND.STS$M_SUCCESS
$ THEN
$ good status
$ ELSE
$ bad status
$ ENDIF

or if you want to test for a specific message number,
$ SEARCH$_NOMATCHES=%X8050

$ IF (stat.AND.STS$M_MSG_NO).EQ.SEARCH$_NOMATCHES
$ THEN
$ nomatches
$ ELSE
$ something else
$ ENDIF

A crucible of informative mistakes