From: Rony G. F. <Ron...@wu...> - 2022-06-12 15:55:25
|
Learned from René that it is possible to use external programs, also Rexx programs in NetRexx pipes like: pipe literal curl http://example.com | command | cons So you can write oo/Rexx filter programs to be used as NetRexx pipe stages. The oo/Rexx filter (reading from stdin, writing to stdout) would have to be written like: do until line="" parse pull line /* read from stdin */ ... do something with line and if you want to pass on data do ... say editedData /* writes to stdout */ end alternatively, one could write the Rexx filter also as (preferable): signal on notready /* raised if stdin gets closed */ do forever parse linein line ... do something with line and if you want to pass on data do ... say editedData /* writes to stdout */ end notready: /* label to jump to */ If you also want to write to stderr then you could either do that in classic Rexx style with "call lineout stderr,data" or in ooRexx ".error~say(data)". You may want to look through these slides: <https://wi.wu.ac.at/rgf/wu/lehre/slides/BusinessProgramming/060_ooRexx_commands_V14.pdf>. ---rony On 6/12/2022 12:47 PM, Rony G. Flatscher wrote: > > Hi Mike, > > sorry a glitch in the demo code that would not check for an asterisk in the first column, here the > corrected (hypothetical and untested code sample: > > command='pipe console | sort | console' -- intensions: read from the console, sort, output to console > arrIn =.array~of("Max", "und", "Moritz", "diese", "beiden", "konnt", "...") > arrOut=.array~new > -- command gets input from ooRexx' arrIn, places stdout into arrOut > ADDRESS SYSTEM command WITH INPUT USING (arrIn) OUTPUT USING (arrOut) > > -- now we need to postprocess the data received from the NetRexx pipe > -- assuming that each line is in the form of "varName=varValue", > -- lines that start with an asterisk (*) get ignored > -- create a directory of varName/varValue entries > dir=.directory~new > do line over arrOut -- process output of pipe line by line > *if left(line,1)="*" then iterate -- ignore lines starting with an asterisk* > parse var line varName '=' varValue > dir~setentry(varName,varValue) -- setentry will uppercase the index varName automatically > end > > -- now you decide what do to with the directory: use it to set Rexx variables in the current > -- context (in this very section of the code) or maybe return it to a caller who could use > -- the directory to set variables in its context > > -- call BsfSetContextVariable("set",dir) -- will set the Rexx variable using dir > -- or: > --return dir -- will return the directory to the caller > > And an additional remark: if it is possible from NetRexx to call external programs in pipes, then > you could always inject ooRexx filters that read from stdin and write to stdout as demonstrated in > the above code. > > HTH, > > ---rony > |