RX return code issue

A forum for general AmigaOS 4.x support questions that are not platform-specific
Post Reply
User avatar
polluks
Posts: 62
Joined: Tue May 19, 2015 7:30 pm
Location: Germany
Contact:

RX return code issue

Post by polluks »

Code: Select all

> RX "exit 42"
> get rc
42
good

Code: Select all

/* 42.rexx */
exit 42

Code: Select all

> RX 42.rexx
> get rc
0
bad
FlynnTheAvatar
Posts: 8
Joined: Thu Aug 11, 2022 1:41 pm

Re: RX return code issue

Post by FlynnTheAvatar »

For reference: this works correctly under classic AmigaOS.
I tested it on 1.3, 2.1, 3.1 (ARexx 1.15) and 3.2.3, and all of them return the correct RC when running RX 42.rexx with a simple exit 42.
So the incorrect return code seems to be specific to the OS4 RX interpreter.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1773
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: RX return code issue

Post by nbache »

@FlynnTheAvatar

Thanks for refreshing this one.

@polluks

When you posted this back in June, I tried to reproduce it, but at first it seemed to work for me. Then I got sidetracked and forgot to do more investigation, sorry.

Now I tried some more, and I think I found a way to reproduce it.

Could you try repeating your test, but in the third step, instead of typing "RX 42.rexx", just type "RX 42".

Does that work correctly?

That's what I found here at least.

If you can confirm, I'll try making a bug report about it. Not sure which component exactly is at fault, though, nor when/if it can be fixed at all in the old ARexx code, but at least we will know the workaround: Omit the .rexx suffix when invoking an ARexx script file (it is optional after all). Yes, I know, crude, but still ...

Oh, and @FlynnTheAvatar: I would be curious to know whether the same difference is present in the classic version. Your comment above seems to indicate it's not, but could you please verify again?

Best regards,

Niels
FlynnTheAvatar
Posts: 8
Joined: Thu Aug 11, 2022 1:41 pm

Re: RX return code issue

Post by FlynnTheAvatar »

@nbache:
I retested with 1.3, 2.1, 3.1 (ARexx 1.15), 3.2.3 (45.9) and 4.1 (52.1):

1.15 and 45.9
RX "EXIT 42" works
RX 42 works
RX 42.rexx works

52.1
RX "EXIT 42" works
RX 42 works
RX 42.rexx does not work, RC = 0
User avatar
polluks
Posts: 62
Joined: Tue May 19, 2015 7:30 pm
Location: Germany
Contact:

Re: RX return code issue

Post by polluks »

Thanks for your feedback!
I noticed RC of implicit RX also fails:

Code: Select all

> protect 42.rexx +s
> 42.rexx
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1773
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: RX return code issue

Post by nbache »

Yes, whereas trying to omit the suffix with implicit Rx just can't find the script.

> 42
42: Ukendt kommando
>

(Unknown command)

The Shell gives a return code of 10 in this case.

Best regards,

Niels
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1773
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: RX return code issue

Post by nbache »

About this last observation: I've had this explained to me by a developer, and it makes sense to me now.

The thing is, when you explicitly invoke a script, it's the Rx command itself that tries to load the script, and it has been coded to know to look for the script on "the ARexx path" (i.e. including in the REXX: assign) with or without the .rexx suffix being given.

However, when you omit the Rx command and just type the script name, it's the Shell that looks for the file, and it cannot guess that you are referring to an ARexx script, so it has to find it with the exact name. Only after checking inside it can it see that it starts with a "/* */" comment, so it will know to submit it for running as an ARexx script. (There are similar rules for scripts with "#! {command}" ("hash-bang") at the start (pass script to that command) and with "#!python" (run as Python program), but those do not require specific file name suffices, so less relevant here).

In short, the behaviour I described above is not a bug, it's just a necessary consequence of the various components at play in the two cases.

As for the original issue with the return codes, it looks to me like it ought to work the same in OS4 as in OS3, and I will try to raise an issue in our bugtracker about it. As usual, no promises, but at least it's probably something related to the OS4 version of the Rx command itself, not the actual ARexx language, (which would be much more unlikely to be fixed).

Side note: Remember that ARexx actually considers such return values as text values, and the conversion to an integer return code (if possible) happens or should happen on returning to the calling (Shell) environment.

Interesting experiments can be made if you try "exit hello" instead of "exit 42", and doing it from a called external ARexx function (a separate script) versus from a script called directly from Rx as we did above.

Also check out the ARexx documentation for Exit versus Return before doing those experiments.

Best regards,

Niels
Post Reply