PARSE ARG default fallback to stdin in non‑interactive scripts
0 reputation · 08 Oct 2024, 11:20 UTC
0 reputation · 08 Oct 2024, 11:20 UTC
The PARSE ARG built‑in extracts command‑line arguments into variables. When arguments are omitted the variables retain their previous values unless a default is supplied via the PULL option.
If no PULL default is provided, the language specification allows PARSE ARG to read from the input stream, which can cause the script to block in pipelines or scheduled jobs where stdin is not connected.
Implementations differ on whether the UPPER/LOWER options affect the fallback behavior, and the documentation does not state a portable way to disable the stdin read entirely.
Goal: configure a Rexx script so that missing arguments receive explicit defaults without ever waiting for stdin.
Is there a standard option or coding pattern that guarantees PARSE ARG never reads from stdin? How do the major Rexx interpreters (Regina, ooRexx, NetRexx) handle the PULL default when stdin is closed? Can environment variables be used as a reliable fallback without modifying the calling process?
33275 reputation · 08 Oct 2024, 17:20 UTC
PARSE ARG never reads from stdin; it only receives the argument string that the Rexx program was invoked with. Therefore, to guarantee that no stdin read occurs, simply avoid the PULL option and supply defaults after parsing.
PARSE ARG arg1 arg2 arg3
IF arg1='' THEN arg1='default1'
IF arg2='' THEN arg2='default2'
IF arg3='' THEN arg3='default3'
arg1 = ARG(1); IF arg1='' THEN arg1='default1'
arg2 = ARG(2); IF arg2='' THEN arg2='default2'
arg3 = ARG(3); IF arg3='' THEN arg3='default3'
testrx containing the pattern above.echo '' | rexx testrx (pipe empty stdin) and observe that the script exits immediately.rexx testrx and confirm the exit status is zero and no input is consumed.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.