I just pushed some changes to master.
With this I am proposing the ADDRESS instruction as an extension to the NetRexx programming language. This opens up NetRexx even more as a general system scripting language, with easy access to anything the operating system provides next to all Java provides. Obviously, it does make such NetRexx programs OS dependent. It is based on the Classic Rexx implementation, best described in 'The OS/2 Procedures Language 2/REXX' << (C) Copyright IBM Corp. 1987, 1994. All Rights Reserved. ──ADDRESS─────┬────────────────────────────┬──;─── ├─environment─┬────────────┬─┤ │ └─expression─┘ │ └┬───────┬───expression1─────┘ └─VALUE─┘ Address is used to send a single command to a specified environment, code an environment, a literal string, or a single symbol, which is taken to be a constant, followed by an expression. The expression is evaluated, and the resulting command string is routed to environment. After the command is executed, environment is set back to whatever it was before, thus temporarily changing the destination for a single command. Example: ADDRESS CMD "DIR C:\STARTUP.CMD" /* OS/2 */ If only environment is specified, a lasting change of destination occurs: all commands that follow (clauses that are neither REXX instructions nor assignment instructions) will be routed to the given command environment, until the next ADDRESS instruction is executed. The previously selected environment is saved. Example: Suppose that the environment for a text editor is registered by the name EDIT: address CMD 'DIR C:\STARTUP.CMD' if rc=0 then 'COPY STARTUP.CMD *.TMP' address EDIT Subsequent commands are passed to the editor until the next ADDRESS instruction. Similarly, you can use the VALUE form to make a lasting change to the environment. Here expression1 (which may be just a variable name) is evaluated, and the result forms the name of the environment. The subkeyword VALUE can be omitted as long as expression1 starts with a special character (so that it cannot be mistaken for a symbol or string). Example: ADDRESS ('ENVIR'||number) With no arguments, commands are routed back to the environment that was selected before the previous lasting change of environment was made, and the current environment name is saved. Repeated execution of ADDRESS alone, therefore, switches the command destination between two environments alternately. A null string for the environment name (" ") is the same as the default environment. >> In the NetRexx implementation, the parser is modified to pick up any clause starting with the ADDRESS instruction, additionally, any unresolved clause will be sent to the ADDRESS environment for 'indirect' execution, provided the environment is set on beforehand. The latter change potentially breaks existing NetRexx programs - without the ADDRESS implementation the compilation would fail. For this, ADDRESS processing is conditioned by the NetRexxC -address flag. Ommitting the -address flag yields the old behavior. Executables set as ADDRESS environment must be found by the OS and need to accept their input on stdin, the output is shown on stdout. Environment can be specified as symbol, literal, local argument or local variable, not as property. The returncode .. ADDRESS VALUE environment (or short ADDRESS environment) can be set in a class or method context. If set in a class context, all indirect execution is sent to the address environment of the class, unless overruled by a ADDRESS VALUE set in method context. Any ADDRESS VALUE set in a method context is lasting until overruled by another ADDRESS VALUE set in the same method context. Direct invocation as in 'ADDRESS bash command' does not change the class of method environment context. There is no default address environment, it must be set before indirect invocation. Switching environments by repeated sole 'ADDRESS' instructions is currently not supported. Invocation of address processing - either directly by 'ADDRESS bash echo Hello world', or indirectly by 'echo Hello world' - must be instructed in a method context. The implementation is unpredictable in multi-threaded programs. Current restrictions: - return code of address invocation is not yet retrievable - exceptions from ProcessBuilder are not yet handled properly Marc A sample: $ cat helloAddress.nrx address bash 'echo Hello world!' $ $ nrc -exec helloAddress -address NetRexx portable processor 4.01-GA build 330-20210118-1901 Copyright (c) RexxLA, 2011,2021. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program helloAddress.nrx ===== Exec: helloAddress ===== Hello world! Processing of 'helloAddress.nrx' complete $ $ cat AddressExample.nrx class AddressExample method main( args=String[] ) static address bash 'echo "Hello world -- direct addressing bash"' address cat 'Hello world -- indirect addressing cat' address '/bin/bash' 'echo "Hello world -- indirect addressing /bin/bash"' 'echo "Hello world -- still indirect addressing /bin/bash"' address value bash AddressByClass() 'echo "Hello world -- still indirect addressing bash"' class AddressByClass address value cat method AddressByClass 'Hello world -- indirect addressing cat by class' address 'bash' 'echo "Hello world -- direct addressing ''bash''"' 'Hello world -- still indirect addressing cat by class' var='bash' address var 'echo "Hello world -- overruled indirect addressing literal by var '||var||'"' hello='Hello world -- overruled indirect addressing a var by 'var say hello hello $ $ nrc -run AddressExample -address NetRexx portable processor 4.01-GA build 330-20210118-1901 Copyright (c) RexxLA, 2011,2021. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program AddressExample.nrx === class AddressExample === function main(String[]) === class AddressByClass === constructor AddressByClass() overrides Object() Compilation of 'AddressExample.nrx' successful [2 classes] Running AddressExample... Hello world -- direct addressing bash Hello world -- indirect addressing cat Hello world -- indirect addressing /bin/bash Hello world -- still indirect addressing /bin/bash Hello world -- indirect addressing cat by class Hello world -- direct addressing 'bash' Hello world -- still indirect addressing cat by class Hello world -- overruled indirect addressing literal by var bash Hello world -- overruled indirect addressing a var by bash Hello world -- still indirect addressing bash $ _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ OpenPGP_signature (505 bytes) Download Attachment |
This was not meant to be a reply to Jason's e-mail, but there you have it.
I also do hope Thomas is OK. Marc On 1/18/21 8:06 PM, Marc Remes wrote: > I just pushed some changes to master. > > With this I am proposing the ADDRESS instruction as an extension to the NetRexx programming language. > This opens up NetRexx even more as a general system scripting language, with easy access to anything the operating > system provides next to all Java provides. > Obviously, it does make such NetRexx programs OS dependent. > > It is based on the Classic Rexx implementation, best described in 'The OS/2 Procedures Language 2/REXX' > > << > (C) Copyright IBM Corp. 1987, 1994. All Rights Reserved. > > ──ADDRESS─────┬────────────────────────────┬──;─── > ├─environment─┬────────────┬─┤ > │ └─expression─┘ │ > └┬───────┬───expression1─────┘ > └─VALUE─┘ > > > Address is used to send a single command to a specified environment, code an environment, a literal string, or a single > symbol, which is taken to be a constant, followed by an expression. The expression is evaluated, and the resulting > command string is routed to environment. After the command is executed, environment is set back to whatever it was > before, thus temporarily changing the destination for a single command. > > Example: > > ADDRESS CMD "DIR C:\STARTUP.CMD" /* OS/2 */ > > If only environment is specified, a lasting change of destination occurs: all commands that follow (clauses that are > neither REXX instructions nor assignment instructions) will be routed to the given command environment, until the next > ADDRESS instruction is executed. The previously selected environment is saved. > > Example: > > Suppose that the environment for a text editor is registered by the name EDIT: > > address CMD > 'DIR C:\STARTUP.CMD' > if rc=0 then 'COPY STARTUP.CMD *.TMP' > address EDIT > > Subsequent commands are passed to the editor until the next ADDRESS instruction. > > Similarly, you can use the VALUE form to make a lasting change to the environment. Here expression1 (which may be just a > variable name) is evaluated, and the result forms the name of the environment. The subkeyword VALUE can be omitted as > long as expression1 starts with a special character (so that it cannot be mistaken for a symbol or string). > > Example: > > ADDRESS ('ENVIR'||number) > > With no arguments, commands are routed back to the environment that was selected before the previous lasting change of > environment was made, and the current environment name is saved. Repeated execution of ADDRESS alone, therefore, > switches the command destination between two environments alternately. A null string for the environment name (" ") is > the same as the default environment. > >> > > In the NetRexx implementation, the parser is modified to pick up any clause starting with the ADDRESS instruction, > additionally, any unresolved clause will be sent to the ADDRESS environment for 'indirect' execution, provided the > environment is set on beforehand. > The latter change potentially breaks existing NetRexx programs - without the ADDRESS implementation the compilation > would fail. > For this, ADDRESS processing is conditioned by the NetRexxC -address flag. Ommitting the -address flag yields the old > behavior. > Executables set as ADDRESS environment must be found by the OS and need to accept their input on stdin, the output is > shown on stdout. > Environment can be specified as symbol, literal, local argument or local variable, not as property. > > The returncode .. > > ADDRESS VALUE environment (or short ADDRESS environment) can be set in a class or method context. > If set in a class context, all indirect execution is sent to the address environment of the class, unless overruled by a > ADDRESS VALUE set in method context. > Any ADDRESS VALUE set in a method context is lasting until overruled by another ADDRESS VALUE set in the same method > context. > Direct invocation as in 'ADDRESS bash command' does not change the class of method environment context. > There is no default address environment, it must be set before indirect invocation. > Switching environments by repeated sole 'ADDRESS' instructions is currently not supported. > > Invocation of address processing - either directly by 'ADDRESS bash echo Hello world', or indirectly by 'echo Hello > world' - must be instructed in a method context. > > The implementation is unpredictable in multi-threaded programs. > > Current restrictions: > - return code of address invocation is not yet retrievable > - exceptions from ProcessBuilder are not yet handled properly > > Marc > > A sample: > > $ cat helloAddress.nrx > > address bash > 'echo Hello world!' > $ > $ nrc -exec helloAddress -address > NetRexx portable processor 4.01-GA build 330-20210118-1901 > Copyright (c) RexxLA, 2011,2021. All rights reserved. > Parts Copyright (c) IBM Corporation, 1995,2008. > Program helloAddress.nrx > ===== Exec: helloAddress ===== > Hello world! > Processing of 'helloAddress.nrx' complete > $ > $ cat AddressExample.nrx > > class AddressExample > method main( args=String[] ) static > > address bash 'echo "Hello world -- direct addressing bash"' > address cat > 'Hello world -- indirect addressing cat' > address '/bin/bash' > 'echo "Hello world -- indirect addressing /bin/bash"' > 'echo "Hello world -- still indirect addressing /bin/bash"' > > address value bash > > AddressByClass() > 'echo "Hello world -- still indirect addressing bash"' > > class AddressByClass > address value cat > > method AddressByClass > 'Hello world -- indirect addressing cat by class' > address 'bash' 'echo "Hello world -- direct addressing ''bash''"' > 'Hello world -- still indirect addressing cat by class' > var='bash' > address var > 'echo "Hello world -- overruled indirect addressing literal by var '||var||'"' > hello='Hello world -- overruled indirect addressing a var by 'var > say hello > hello > $ > $ nrc -run AddressExample -address > NetRexx portable processor 4.01-GA build 330-20210118-1901 > Copyright (c) RexxLA, 2011,2021. All rights reserved. > Parts Copyright (c) IBM Corporation, 1995,2008. > Program AddressExample.nrx > === class AddressExample === > function main(String[]) > > === class AddressByClass === > constructor AddressByClass() > overrides Object() > Compilation of 'AddressExample.nrx' successful [2 classes] > Running AddressExample... > Hello world -- direct addressing bash > Hello world -- indirect addressing cat > Hello world -- indirect addressing /bin/bash > Hello world -- still indirect addressing /bin/bash > Hello world -- indirect addressing cat by class > Hello world -- direct addressing 'bash' > Hello world -- still indirect addressing cat by class > Hello world -- overruled indirect addressing literal by var bash > Hello world -- overruled indirect addressing a var by bash > Hello world -- still indirect addressing bash > $ > > > _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ OpenPGP_signature (505 bytes) Download Attachment |
Using my pre-retirement alter ego I have moved your original post into its
own category Ian -- Sent from: https://urldefense.proofpoint.com/v2/url?u=http-3A__ibm-2Dnetrexx.215625.n3.nabble.com_&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=KADhlbsvBQ5L7f2759OhWU1U03ieSGUNRFlkagljKJg&s=Bs9HfubM_QvtE59m19RFmN4sgCyy9KrLmuUwFBvIv6s&e= _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Marc Remes-2
Hi Marc,
*very nice* and *impressive*, kudos to you! One little suggestion though: allow an environment name like SYSTEM or the empty string '' to indicate to use the default shell defined for the host operating system (i.e., cmd.exe on Windows or $SHELL on Unix with a fallback to /bin/sh). This way one can issue commands from NetRexx where the authors do not know which shell is responsible/available to handle the command. Cheers ---rony P.S.: Of course, having the redirection ability of stdin, stdout and stderr like Regina or ooRexx 5 would be an additional boon (yes, with eating the appetite grows ... ;) ) e.g. using ArrayLists instead which also would allow the recturn code of the command to be available (ooRexx introduces the USING subkeyword for indicating the collection object to be used for redirection). But one step after the other. :-) On 18.01.2021 20:06, Marc Remes wrote: > I just pushed some changes to master. > > With this I am proposing the ADDRESS instruction as an extension to the NetRexx programming language. > This opens up NetRexx even more as a general system scripting language, with easy access to > anything the operating system provides next to all Java provides. > Obviously, it does make such NetRexx programs OS dependent. > > It is based on the Classic Rexx implementation, best described in 'The OS/2 Procedures Language > 2/REXX' > > << > (C) Copyright IBM Corp. 1987, 1994. All Rights Reserved. > > ──ADDRESS─────┬────────────────────────────┬──;─── > ├─environment─┬────────────┬─┤ > │ └─expression─┘ │ > └┬───────┬───expression1─────┘ > └─VALUE─┘ > > > Address is used to send a single command to a specified environment, code an environment, a > literal string, or a single symbol, which is taken to be a constant, followed by an expression. > The expression is evaluated, and the resulting command string is routed to environment. After the > command is executed, environment is set back to whatever it was before, thus temporarily changing > the destination for a single command. > > Example: > > ADDRESS CMD "DIR C:\STARTUP.CMD" /* OS/2 */ > > If only environment is specified, a lasting change of destination occurs: all commands that follow > (clauses that are neither REXX instructions nor assignment instructions) will be routed to the > given command environment, until the next ADDRESS instruction is executed. The previously selected > environment is saved. > > Example: > > Suppose that the environment for a text editor is registered by the name EDIT: > > address CMD > 'DIR C:\STARTUP.CMD' > if rc=0 then 'COPY STARTUP.CMD *.TMP' > address EDIT > > Subsequent commands are passed to the editor until the next ADDRESS instruction. > > Similarly, you can use the VALUE form to make a lasting change to the environment. Here > expression1 (which may be just a variable name) is evaluated, and the result forms the name of the > environment. The subkeyword VALUE can be omitted as long as expression1 starts with a special > character (so that it cannot be mistaken for a symbol or string). > > Example: > > ADDRESS ('ENVIR'||number) > > With no arguments, commands are routed back to the environment that was selected before the > previous lasting change of environment was made, and the current environment name is saved. > Repeated execution of ADDRESS alone, therefore, switches the command destination between two > environments alternately. A null string for the environment name (" ") is the same as the default > environment. > >> > > In the NetRexx implementation, the parser is modified to pick up any clause starting with the > ADDRESS instruction, additionally, any unresolved clause will be sent to the ADDRESS environment > for 'indirect' execution, provided the environment is set on beforehand. > The latter change potentially breaks existing NetRexx programs - without the ADDRESS > implementation the compilation would fail. > For this, ADDRESS processing is conditioned by the NetRexxC -address flag. Ommitting the -address > flag yields the old behavior. > Executables set as ADDRESS environment must be found by the OS and need to accept their input on > stdin, the output is shown on stdout. > Environment can be specified as symbol, literal, local argument or local variable, not as property. > > The returncode .. > > ADDRESS VALUE environment (or short ADDRESS environment) can be set in a class or method context. > If set in a class context, all indirect execution is sent to the address environment of the class, > unless overruled by a ADDRESS VALUE set in method context. > Any ADDRESS VALUE set in a method context is lasting until overruled by another ADDRESS VALUE set > in the same method context. > Direct invocation as in 'ADDRESS bash command' does not change the class of method environment > context. > There is no default address environment, it must be set before indirect invocation. > Switching environments by repeated sole 'ADDRESS' instructions is currently not supported. > > Invocation of address processing - either directly by 'ADDRESS bash echo Hello world', or > indirectly by 'echo Hello world' - must be instructed in a method context. > > The implementation is unpredictable in multi-threaded programs. > > Current restrictions: > - return code of address invocation is not yet retrievable > - exceptions from ProcessBuilder are not yet handled properly > > Marc > > A sample: > > $ cat helloAddress.nrx > > address bash > 'echo Hello world!' > $ > $ nrc -exec helloAddress -address > NetRexx portable processor 4.01-GA build 330-20210118-1901 > Copyright (c) RexxLA, 2011,2021. All rights reserved. > Parts Copyright (c) IBM Corporation, 1995,2008. > Program helloAddress.nrx > ===== Exec: helloAddress ===== > Hello world! > Processing of 'helloAddress.nrx' complete > $ > $ cat AddressExample.nrx > > class AddressExample > method main( args=String[] ) static > > address bash 'echo "Hello world -- direct addressing bash"' > address cat > 'Hello world -- indirect addressing cat' > address '/bin/bash' > 'echo "Hello world -- indirect addressing /bin/bash"' > 'echo "Hello world -- still indirect addressing /bin/bash"' > > address value bash > > AddressByClass() > 'echo "Hello world -- still indirect addressing bash"' > > class AddressByClass > address value cat > > method AddressByClass > 'Hello world -- indirect addressing cat by class' > address 'bash' 'echo "Hello world -- direct addressing ''bash''"' > 'Hello world -- still indirect addressing cat by class' > var='bash' > address var > 'echo "Hello world -- overruled indirect addressing literal by var '||var||'"' > hello='Hello world -- overruled indirect addressing a var by 'var > say hello > hello > $ > $ nrc -run AddressExample -address > NetRexx portable processor 4.01-GA build 330-20210118-1901 > Copyright (c) RexxLA, 2011,2021. All rights reserved. > Parts Copyright (c) IBM Corporation, 1995,2008. > Program AddressExample.nrx > === class AddressExample === > function main(String[]) > > === class AddressByClass === > constructor AddressByClass() > overrides Object() > Compilation of 'AddressExample.nrx' successful [2 classes] > Running AddressExample... > Hello world -- direct addressing bash > Hello world -- indirect addressing cat > Hello world -- indirect addressing /bin/bash > Hello world -- still indirect addressing /bin/bash > Hello world -- indirect addressing cat by class > Hello world -- direct addressing 'bash' > Hello world -- still indirect addressing cat by class > Hello world -- overruled indirect addressing literal by var bash > Hello world -- overruled indirect addressing a var by bash > Hello world -- still indirect addressing bash > $ > _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Thanks Rony.
SYSTEM or '' would deviate from the Classic Rexx implementation, but I see oorexx supports SYSTEM. It's doable: windows %COMSPEC%, linux & macos $SHELL, other /bin/sh On the returncode, I was thinking to create a new special word rc, any address invocation would store the exit code on RxMethod level from where the rc special word would retrieve - still have to figure out how to do that however; This stays as close to Classic Rexx as possible. And I don't think it would break any existing code, per pg 39 of the Language Reference: << Special names and methods For convenience, NetRexx provides some special names for naming commonly-used concepts within terms. These are only recognized if there is no variable of the same name previously seen in the current scope ... >> Ideas are welcome. Redir.. indeed, one step at the time; Marc On 1/19/21 12:32 PM, Rony G. Flatscher wrote: > Hi Marc, > > *very nice* and *impressive*, kudos to you! > > One little suggestion though: allow an environment name like SYSTEM or the empty string '' to > indicate to use the default shell defined for the host operating system (i.e., cmd.exe on Windows or > $SHELL on Unix with a fallback to /bin/sh). This way one can issue commands from NetRexx where the > authors do not know which shell is responsible/available to handle the command. > > Cheers > > ---rony > > P.S.: Of course, having the redirection ability of stdin, stdout and stderr like Regina or ooRexx 5 > would be an additional boon (yes, with eating the appetite grows ... ;) ) e.g. using ArrayLists > instead which also would allow the recturn code of the command to be available (ooRexx introduces > the USING subkeyword for indicating the collection object to be used for redirection). But one step > after the other. :-) > > > > On 18.01.2021 20:06, Marc Remes wrote: >> I just pushed some changes to master. >> >> With this I am proposing the ADDRESS instruction as an extension to the NetRexx programming language. >> This opens up NetRexx even more as a general system scripting language, with easy access to >> anything the operating system provides next to all Java provides. >> Obviously, it does make such NetRexx programs OS dependent. >> >> It is based on the Classic Rexx implementation, best described in 'The OS/2 Procedures Language >> 2/REXX' >> >> << >> (C) Copyright IBM Corp. 1987, 1994. All Rights Reserved. >> >> ──ADDRESS─────┬────────────────────────────┬──;─── >> ├─environment─┬────────────┬─┤ >> │ └─expression─┘ │ >> └┬───────┬───expression1─────┘ >> └─VALUE─┘ >> >> >> Address is used to send a single command to a specified environment, code an environment, a >> literal string, or a single symbol, which is taken to be a constant, followed by an expression. >> The expression is evaluated, and the resulting command string is routed to environment. After the >> command is executed, environment is set back to whatever it was before, thus temporarily changing >> the destination for a single command. >> >> Example: >> >> ADDRESS CMD "DIR C:\STARTUP.CMD" /* OS/2 */ >> >> If only environment is specified, a lasting change of destination occurs: all commands that follow >> (clauses that are neither REXX instructions nor assignment instructions) will be routed to the >> given command environment, until the next ADDRESS instruction is executed. The previously selected >> environment is saved. >> >> Example: >> >> Suppose that the environment for a text editor is registered by the name EDIT: >> >> address CMD >> 'DIR C:\STARTUP.CMD' >> if rc=0 then 'COPY STARTUP.CMD *.TMP' >> address EDIT >> >> Subsequent commands are passed to the editor until the next ADDRESS instruction. >> >> Similarly, you can use the VALUE form to make a lasting change to the environment. Here >> expression1 (which may be just a variable name) is evaluated, and the result forms the name of the >> environment. The subkeyword VALUE can be omitted as long as expression1 starts with a special >> character (so that it cannot be mistaken for a symbol or string). >> >> Example: >> >> ADDRESS ('ENVIR'||number) >> >> With no arguments, commands are routed back to the environment that was selected before the >> previous lasting change of environment was made, and the current environment name is saved. >> Repeated execution of ADDRESS alone, therefore, switches the command destination between two >> environments alternately. A null string for the environment name (" ") is the same as the default >> environment. >>>> >> >> In the NetRexx implementation, the parser is modified to pick up any clause starting with the >> ADDRESS instruction, additionally, any unresolved clause will be sent to the ADDRESS environment >> for 'indirect' execution, provided the environment is set on beforehand. >> The latter change potentially breaks existing NetRexx programs - without the ADDRESS >> implementation the compilation would fail. >> For this, ADDRESS processing is conditioned by the NetRexxC -address flag. Ommitting the -address >> flag yields the old behavior. >> Executables set as ADDRESS environment must be found by the OS and need to accept their input on >> stdin, the output is shown on stdout. >> Environment can be specified as symbol, literal, local argument or local variable, not as property. >> >> The returncode .. >> >> ADDRESS VALUE environment (or short ADDRESS environment) can be set in a class or method context. >> If set in a class context, all indirect execution is sent to the address environment of the class, >> unless overruled by a ADDRESS VALUE set in method context. >> Any ADDRESS VALUE set in a method context is lasting until overruled by another ADDRESS VALUE set >> in the same method context. >> Direct invocation as in 'ADDRESS bash command' does not change the class of method environment >> context. >> There is no default address environment, it must be set before indirect invocation. >> Switching environments by repeated sole 'ADDRESS' instructions is currently not supported. >> >> Invocation of address processing - either directly by 'ADDRESS bash echo Hello world', or >> indirectly by 'echo Hello world' - must be instructed in a method context. >> >> The implementation is unpredictable in multi-threaded programs. >> >> Current restrictions: >> - return code of address invocation is not yet retrievable >> - exceptions from ProcessBuilder are not yet handled properly >> >> Marc >> >> A sample: >> >> $ cat helloAddress.nrx >> >> address bash >> 'echo Hello world!' >> $ >> $ nrc -exec helloAddress -address >> NetRexx portable processor 4.01-GA build 330-20210118-1901 >> Copyright (c) RexxLA, 2011,2021. All rights reserved. >> Parts Copyright (c) IBM Corporation, 1995,2008. >> Program helloAddress.nrx >> ===== Exec: helloAddress ===== >> Hello world! >> Processing of 'helloAddress.nrx' complete >> $ >> $ cat AddressExample.nrx >> >> class AddressExample >> method main( args=String[] ) static >> >> address bash 'echo "Hello world -- direct addressing bash"' >> address cat >> 'Hello world -- indirect addressing cat' >> address '/bin/bash' >> 'echo "Hello world -- indirect addressing /bin/bash"' >> 'echo "Hello world -- still indirect addressing /bin/bash"' >> >> address value bash >> >> AddressByClass() >> 'echo "Hello world -- still indirect addressing bash"' >> >> class AddressByClass >> address value cat >> >> method AddressByClass >> 'Hello world -- indirect addressing cat by class' >> address 'bash' 'echo "Hello world -- direct addressing ''bash''"' >> 'Hello world -- still indirect addressing cat by class' >> var='bash' >> address var >> 'echo "Hello world -- overruled indirect addressing literal by var '||var||'"' >> hello='Hello world -- overruled indirect addressing a var by 'var >> say hello >> hello >> $ >> $ nrc -run AddressExample -address >> NetRexx portable processor 4.01-GA build 330-20210118-1901 >> Copyright (c) RexxLA, 2011,2021. All rights reserved. >> Parts Copyright (c) IBM Corporation, 1995,2008. >> Program AddressExample.nrx >> === class AddressExample === >> function main(String[]) >> >> === class AddressByClass === >> constructor AddressByClass() >> overrides Object() >> Compilation of 'AddressExample.nrx' successful [2 classes] >> Running AddressExample... >> Hello world -- direct addressing bash >> Hello world -- indirect addressing cat >> Hello world -- indirect addressing /bin/bash >> Hello world -- still indirect addressing /bin/bash >> Hello world -- indirect addressing cat by class >> Hello world -- direct addressing 'bash' >> Hello world -- still indirect addressing cat by class >> Hello world -- overruled indirect addressing literal by var bash >> Hello world -- overruled indirect addressing a var by bash >> Hello world -- still indirect addressing bash >> $ >> > > _______________________________________________ > Ibm-netrexx mailing list > [hidden email] > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ > _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ OpenPGP_signature (505 bytes) Download Attachment |
Redir: we have redir in RexxIO - could be used.
René. > On 19 Jan 2021, at 13:48, Marc Remes <[hidden email]> wrote: > > Thanks Rony. > > SYSTEM or '' would deviate from the Classic Rexx implementation, but I see oorexx supports SYSTEM. > It's doable: windows %COMSPEC%, linux & macos $SHELL, other /bin/sh > > On the returncode, I was thinking to create a new special word rc, any address invocation would > store the exit code on RxMethod level from where the rc special word would retrieve - still > have to figure out how to do that however; > This stays as close to Classic Rexx as possible. > And I don't think it would break any existing code, per pg 39 of the Language Reference: > << > Special names and methods > For convenience, NetRexx provides some special names for naming commonly-used > concepts within terms. These are only recognized if there is no variable of the same name > previously seen in the current scope ... > >> > Ideas are welcome. > > Redir.. indeed, one step at the time; > > Marc > > On 1/19/21 12:32 PM, Rony G. Flatscher wrote: >> Hi Marc, >> *very nice* and *impressive*, kudos to you! >> One little suggestion though: allow an environment name like SYSTEM or the empty string '' to >> indicate to use the default shell defined for the host operating system (i.e., cmd.exe on Windows or >> $SHELL on Unix with a fallback to /bin/sh). This way one can issue commands from NetRexx where the >> authors do not know which shell is responsible/available to handle the command. >> Cheers >> ---rony >> P.S.: Of course, having the redirection ability of stdin, stdout and stderr like Regina or ooRexx 5 >> would be an additional boon (yes, with eating the appetite grows ... ;) ) e.g. using ArrayLists >> instead which also would allow the recturn code of the command to be available (ooRexx introduces >> the USING subkeyword for indicating the collection object to be used for redirection). But one step >> after the other. :-) >> On 18.01.2021 20:06, Marc Remes wrote: >>> I just pushed some changes to master. >>> >>> With this I am proposing the ADDRESS instruction as an extension to the NetRexx programming language. >>> This opens up NetRexx even more as a general system scripting language, with easy access to >>> anything the operating system provides next to all Java provides. >>> Obviously, it does make such NetRexx programs OS dependent. >>> >>> It is based on the Classic Rexx implementation, best described in 'The OS/2 Procedures Language >>> 2/REXX' >>> >>> << >>> (C) Copyright IBM Corp. 1987, 1994. All Rights Reserved. >>> >>> ──ADDRESS─────┬────────────────────────────┬──;─── >>> ├─environment─┬────────────┬─┤ >>> │ └─expression─┘ │ >>> └┬───────┬───expression1─────┘ >>> └─VALUE─┘ >>> >>> >>> Address is used to send a single command to a specified environment, code an environment, a >>> literal string, or a single symbol, which is taken to be a constant, followed by an expression. >>> The expression is evaluated, and the resulting command string is routed to environment. After the >>> command is executed, environment is set back to whatever it was before, thus temporarily changing >>> the destination for a single command. >>> >>> Example: >>> >>> ADDRESS CMD "DIR C:\STARTUP.CMD" /* OS/2 */ >>> >>> If only environment is specified, a lasting change of destination occurs: all commands that follow >>> (clauses that are neither REXX instructions nor assignment instructions) will be routed to the >>> given command environment, until the next ADDRESS instruction is executed. The previously selected >>> environment is saved. >>> >>> Example: >>> >>> Suppose that the environment for a text editor is registered by the name EDIT: >>> >>> address CMD >>> 'DIR C:\STARTUP.CMD' >>> if rc=0 then 'COPY STARTUP.CMD *.TMP' >>> address EDIT >>> >>> Subsequent commands are passed to the editor until the next ADDRESS instruction. >>> >>> Similarly, you can use the VALUE form to make a lasting change to the environment. Here >>> expression1 (which may be just a variable name) is evaluated, and the result forms the name of the >>> environment. The subkeyword VALUE can be omitted as long as expression1 starts with a special >>> character (so that it cannot be mistaken for a symbol or string). >>> >>> Example: >>> >>> ADDRESS ('ENVIR'||number) >>> >>> With no arguments, commands are routed back to the environment that was selected before the >>> previous lasting change of environment was made, and the current environment name is saved. >>> Repeated execution of ADDRESS alone, therefore, switches the command destination between two >>> environments alternately. A null string for the environment name (" ") is the same as the default >>> environment. >>>>> >>> >>> In the NetRexx implementation, the parser is modified to pick up any clause starting with the >>> ADDRESS instruction, additionally, any unresolved clause will be sent to the ADDRESS environment >>> for 'indirect' execution, provided the environment is set on beforehand. >>> The latter change potentially breaks existing NetRexx programs - without the ADDRESS >>> implementation the compilation would fail. >>> For this, ADDRESS processing is conditioned by the NetRexxC -address flag. Ommitting the -address >>> flag yields the old behavior. >>> Executables set as ADDRESS environment must be found by the OS and need to accept their input on >>> stdin, the output is shown on stdout. >>> Environment can be specified as symbol, literal, local argument or local variable, not as property. >>> >>> The returncode .. >>> >>> ADDRESS VALUE environment (or short ADDRESS environment) can be set in a class or method context. >>> If set in a class context, all indirect execution is sent to the address environment of the class, >>> unless overruled by a ADDRESS VALUE set in method context. >>> Any ADDRESS VALUE set in a method context is lasting until overruled by another ADDRESS VALUE set >>> in the same method context. >>> Direct invocation as in 'ADDRESS bash command' does not change the class of method environment >>> context. >>> There is no default address environment, it must be set before indirect invocation. >>> Switching environments by repeated sole 'ADDRESS' instructions is currently not supported. >>> >>> Invocation of address processing - either directly by 'ADDRESS bash echo Hello world', or >>> indirectly by 'echo Hello world' - must be instructed in a method context. >>> >>> The implementation is unpredictable in multi-threaded programs. >>> >>> Current restrictions: >>> - return code of address invocation is not yet retrievable >>> - exceptions from ProcessBuilder are not yet handled properly >>> >>> Marc >>> >>> A sample: >>> >>> $ cat helloAddress.nrx >>> >>> address bash >>> 'echo Hello world!' >>> $ >>> $ nrc -exec helloAddress -address >>> NetRexx portable processor 4.01-GA build 330-20210118-1901 >>> Copyright (c) RexxLA, 2011,2021. All rights reserved. >>> Parts Copyright (c) IBM Corporation, 1995,2008. >>> Program helloAddress.nrx >>> ===== Exec: helloAddress ===== >>> Hello world! >>> Processing of 'helloAddress.nrx' complete >>> $ >>> $ cat AddressExample.nrx >>> >>> class AddressExample >>> method main( args=String[] ) static >>> >>> address bash 'echo "Hello world -- direct addressing bash"' >>> address cat >>> 'Hello world -- indirect addressing cat' >>> address '/bin/bash' >>> 'echo "Hello world -- indirect addressing /bin/bash"' >>> 'echo "Hello world -- still indirect addressing /bin/bash"' >>> >>> address value bash >>> >>> AddressByClass() >>> 'echo "Hello world -- still indirect addressing bash"' >>> >>> class AddressByClass >>> address value cat >>> >>> method AddressByClass >>> 'Hello world -- indirect addressing cat by class' >>> address 'bash' 'echo "Hello world -- direct addressing ''bash''"' >>> 'Hello world -- still indirect addressing cat by class' >>> var='bash' >>> address var >>> 'echo "Hello world -- overruled indirect addressing literal by var '||var||'"' >>> hello='Hello world -- overruled indirect addressing a var by 'var >>> say hello >>> hello >>> $ >>> $ nrc -run AddressExample -address >>> NetRexx portable processor 4.01-GA build 330-20210118-1901 >>> Copyright (c) RexxLA, 2011,2021. All rights reserved. >>> Parts Copyright (c) IBM Corporation, 1995,2008. >>> Program AddressExample.nrx >>> === class AddressExample === >>> function main(String[]) >>> >>> === class AddressByClass === >>> constructor AddressByClass() >>> overrides Object() >>> Compilation of 'AddressExample.nrx' successful [2 classes] >>> Running AddressExample... >>> Hello world -- direct addressing bash >>> Hello world -- indirect addressing cat >>> Hello world -- indirect addressing /bin/bash >>> Hello world -- still indirect addressing /bin/bash >>> Hello world -- indirect addressing cat by class >>> Hello world -- direct addressing 'bash' >>> Hello world -- still indirect addressing cat by class >>> Hello world -- overruled indirect addressing literal by var bash >>> Hello world -- overruled indirect addressing a var by bash >>> Hello world -- still indirect addressing bash >>> $ >>> >> _______________________________________________ >> Ibm-netrexx mailing list >> [hidden email] >> Online Archive : https://urldefense.proofpoint.com/v2/url?u=http-3A__ibm-2Dnetrexx.215625.n3.nabble.com_&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=vl7HwnKE2oDVEJ8rWVuxnRxp6wwX-CV7VR7utTel1A0&s=KwM7dewlLdXPIrI175QwNW4zs5s0IKtZ1BwkB3cMV3M&e= > > _______________________________________________ > Ibm-netrexx mailing list > [hidden email] > Online Archive : https://urldefense.proofpoint.com/v2/url?u=http-3A__ibm-2Dnetrexx.215625.n3.nabble.com_&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=vl7HwnKE2oDVEJ8rWVuxnRxp6wwX-CV7VR7utTel1A0&s=KwM7dewlLdXPIrI175QwNW4zs5s0IKtZ1BwkB3cMV3M&e= > _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Rony G. Flatscher
I pushed some updates:
- ADDRESS SYSTEM does the needed - Collect RC as exitcode from last ADDRESS invocation Another sample : $ cat helloAddress.nrx address system 'echo Hello world!' exit='exit 7' exit say 'rc='rc $ $ nrc -exec helloAddress -address NetRexx portable processor 4.01-GA build 419-20210120-1527 Copyright (c) RexxLA, 2011,2021. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program helloAddress.nrx ===== Exec: helloAddress ===== Hello world! rc=7 Processing of 'helloAddress.nrx' complete $ Marc On 1/19/21 12:32 PM, Rony G. Flatscher wrote: > Hi Marc, > > *very nice* and *impressive*, kudos to you! > > One little suggestion though: allow an environment name like SYSTEM or the empty string '' to > indicate to use the default shell defined for the host operating system (i.e., cmd.exe on Windows or > $SHELL on Unix with a fallback to /bin/sh). This way one can issue commands from NetRexx where the > authors do not know which shell is responsible/available to handle the command. > > Cheers > > ---rony > > P.S.: Of course, having the redirection ability of stdin, stdout and stderr like Regina or ooRexx 5 > would be an additional boon (yes, with eating the appetite grows ... ;) ) e.g. using ArrayLists > instead which also would allow the recturn code of the command to be available (ooRexx introduces > the USING subkeyword for indicating the collection object to be used for redirection). But one step > after the other. :-) > > > > On 18.01.2021 20:06, Marc Remes wrote: >> I just pushed some changes to master. >> >> With this I am proposing the ADDRESS instruction as an extension to the NetRexx programming language. >> This opens up NetRexx even more as a general system scripting language, with easy access to >> anything the operating system provides next to all Java provides. >> Obviously, it does make such NetRexx programs OS dependent. >> >> It is based on the Classic Rexx implementation, best described in 'The OS/2 Procedures Language >> 2/REXX' >> >> << >> (C) Copyright IBM Corp. 1987, 1994. All Rights Reserved. >> >> ──ADDRESS─────┬────────────────────────────┬──;─── >> ├─environment─┬────────────┬─┤ >> │ └─expression─┘ │ >> └┬───────┬───expression1─────┘ >> └─VALUE─┘ >> >> >> Address is used to send a single command to a specified environment, code an environment, a >> literal string, or a single symbol, which is taken to be a constant, followed by an expression. >> The expression is evaluated, and the resulting command string is routed to environment. After the >> command is executed, environment is set back to whatever it was before, thus temporarily changing >> the destination for a single command. >> >> Example: >> >> ADDRESS CMD "DIR C:\STARTUP.CMD" /* OS/2 */ >> >> If only environment is specified, a lasting change of destination occurs: all commands that follow >> (clauses that are neither REXX instructions nor assignment instructions) will be routed to the >> given command environment, until the next ADDRESS instruction is executed. The previously selected >> environment is saved. >> >> Example: >> >> Suppose that the environment for a text editor is registered by the name EDIT: >> >> address CMD >> 'DIR C:\STARTUP.CMD' >> if rc=0 then 'COPY STARTUP.CMD *.TMP' >> address EDIT >> >> Subsequent commands are passed to the editor until the next ADDRESS instruction. >> >> Similarly, you can use the VALUE form to make a lasting change to the environment. Here >> expression1 (which may be just a variable name) is evaluated, and the result forms the name of the >> environment. The subkeyword VALUE can be omitted as long as expression1 starts with a special >> character (so that it cannot be mistaken for a symbol or string). >> >> Example: >> >> ADDRESS ('ENVIR'||number) >> >> With no arguments, commands are routed back to the environment that was selected before the >> previous lasting change of environment was made, and the current environment name is saved. >> Repeated execution of ADDRESS alone, therefore, switches the command destination between two >> environments alternately. A null string for the environment name (" ") is the same as the default >> environment. >>>> >> >> In the NetRexx implementation, the parser is modified to pick up any clause starting with the >> ADDRESS instruction, additionally, any unresolved clause will be sent to the ADDRESS environment >> for 'indirect' execution, provided the environment is set on beforehand. >> The latter change potentially breaks existing NetRexx programs - without the ADDRESS >> implementation the compilation would fail. >> For this, ADDRESS processing is conditioned by the NetRexxC -address flag. Ommitting the -address >> flag yields the old behavior. >> Executables set as ADDRESS environment must be found by the OS and need to accept their input on >> stdin, the output is shown on stdout. >> Environment can be specified as symbol, literal, local argument or local variable, not as property. >> >> The returncode .. >> >> ADDRESS VALUE environment (or short ADDRESS environment) can be set in a class or method context. >> If set in a class context, all indirect execution is sent to the address environment of the class, >> unless overruled by a ADDRESS VALUE set in method context. >> Any ADDRESS VALUE set in a method context is lasting until overruled by another ADDRESS VALUE set >> in the same method context. >> Direct invocation as in 'ADDRESS bash command' does not change the class of method environment >> context. >> There is no default address environment, it must be set before indirect invocation. >> Switching environments by repeated sole 'ADDRESS' instructions is currently not supported. >> >> Invocation of address processing - either directly by 'ADDRESS bash echo Hello world', or >> indirectly by 'echo Hello world' - must be instructed in a method context. >> >> The implementation is unpredictable in multi-threaded programs. >> >> Current restrictions: >> - return code of address invocation is not yet retrievable >> - exceptions from ProcessBuilder are not yet handled properly >> >> Marc >> >> A sample: >> >> $ cat helloAddress.nrx >> >> address bash >> 'echo Hello world!' >> $ >> $ nrc -exec helloAddress -address >> NetRexx portable processor 4.01-GA build 330-20210118-1901 >> Copyright (c) RexxLA, 2011,2021. All rights reserved. >> Parts Copyright (c) IBM Corporation, 1995,2008. >> Program helloAddress.nrx >> ===== Exec: helloAddress ===== >> Hello world! >> Processing of 'helloAddress.nrx' complete >> $ >> $ cat AddressExample.nrx >> >> class AddressExample >> method main( args=String[] ) static >> >> address bash 'echo "Hello world -- direct addressing bash"' >> address cat >> 'Hello world -- indirect addressing cat' >> address '/bin/bash' >> 'echo "Hello world -- indirect addressing /bin/bash"' >> 'echo "Hello world -- still indirect addressing /bin/bash"' >> >> address value bash >> >> AddressByClass() >> 'echo "Hello world -- still indirect addressing bash"' >> >> class AddressByClass >> address value cat >> >> method AddressByClass >> 'Hello world -- indirect addressing cat by class' >> address 'bash' 'echo "Hello world -- direct addressing ''bash''"' >> 'Hello world -- still indirect addressing cat by class' >> var='bash' >> address var >> 'echo "Hello world -- overruled indirect addressing literal by var '||var||'"' >> hello='Hello world -- overruled indirect addressing a var by 'var >> say hello >> hello >> $ >> $ nrc -run AddressExample -address >> NetRexx portable processor 4.01-GA build 330-20210118-1901 >> Copyright (c) RexxLA, 2011,2021. All rights reserved. >> Parts Copyright (c) IBM Corporation, 1995,2008. >> Program AddressExample.nrx >> === class AddressExample === >> function main(String[]) >> >> === class AddressByClass === >> constructor AddressByClass() >> overrides Object() >> Compilation of 'AddressExample.nrx' successful [2 classes] >> Running AddressExample... >> Hello world -- direct addressing bash >> Hello world -- indirect addressing cat >> Hello world -- indirect addressing /bin/bash >> Hello world -- still indirect addressing /bin/bash >> Hello world -- indirect addressing cat by class >> Hello world -- direct addressing 'bash' >> Hello world -- still indirect addressing cat by class >> Hello world -- overruled indirect addressing literal by var bash >> Hello world -- overruled indirect addressing a var by bash >> Hello world -- still indirect addressing bash >> $ >> > > _______________________________________________ > Ibm-netrexx mailing list > [hidden email] > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ > _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ OpenPGP_signature (505 bytes) Download Attachment |
Very cool, Marc, thank you very much!
---rony On 20.01.2021 15:40, Marc Remes wrote: > I pushed some updates: > > - ADDRESS SYSTEM does the needed > - Collect RC as exitcode from last ADDRESS invocation > > Another sample : > > $ cat helloAddress.nrx > > address system > 'echo Hello world!' > > exit='exit 7' > exit > say 'rc='rc > $ > $ nrc -exec helloAddress -address > NetRexx portable processor 4.01-GA build 419-20210120-1527 > Copyright (c) RexxLA, 2011,2021. All rights reserved. > Parts Copyright (c) IBM Corporation, 1995,2008. > Program helloAddress.nrx > ===== Exec: helloAddress ===== > Hello world! > rc=7 > Processing of 'helloAddress.nrx' complete > $ > > Marc _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Marc Remes-2
Marc, THANK YOU! I'm thinking of some uses in Pipelines for the future, that currently need some stepping around. Jeff On 1/20/2021 9:40 AM, Marc Remes wrote:
I pushed some updates: _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |