In windows 2000, catching error output is not obvious because you lose the error code returned by command, for example suppose I want to execute MYPROG from within a oorexx macro :
//
command = "MYPROG 2>&1 | RXQUEUE"
ADDRESS CMD command
say RC
do i = 1 to queued()
pull line
say line
end
/ --- /
if MYPROG fails logically and returns a code, it will be lost by OOREXX, where RC value will always be = 0 (even if you get the output console)
This contrast with regina rexx
ADDRESS SYSTEM cmd WITH OUTPUT STEM rescmd. ERROR STEM errcmd.
where you get stderr in errcmd. stem, and the external program return code
As documentation is not very clear, does anyone has a solution ?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In windows 2000, catching error output is not obvious because you lose the error code returned by command, for example suppose I want to execute MYPROG from within a oorexx macro :
/ /
command = "MYPROG 2>&1 | RXQUEUE"
ADDRESS CMD command
say RC
do i = 1 to queued()
pull line
say line
end
/ --- /
if MYPROG fails logically and returns a code, it will be lost by OOREXX, where RC value will always be = 0 (even if you get the output console)
This contrast with regina rexx
ADDRESS SYSTEM cmd WITH OUTPUT STEM rescmd. ERROR STEM errcmd.
where you get stderr in errcmd. stem, and the external program return code
As documentation is not very clear, does anyone has a solution ?
Thanks.
Since Rick has been answering most of these, I'll try to catch this one. (Unfortunately, Rick is usually quicker than I am. <grin>)
The problem here is that RXQUEUE is an executable program and it is the last to execute. So the return code is the code from RXQUEUE, not your MYPROG.
There is not much that can change that with the current ooRexx. The solution is to not use RXQUEUE.
If you don't need the output, then redirect to null. On Windows you do that with something like:
command = "MYPROG 1>nul 2>&1"
command
say RC
I usually don't use ADDRESS, but just pass the string to the outside environment.
When I need to capture the output for some reason, I redirect to a temp file, read the file, delete the file. Something like this:
command = "MYPROG > MyFileName.temp 2>&1"
command
realRC = RC
fsObj = .stream~new('MyFileName.temp')
output = fsObj~arrayin
say 'MYPROG returns:' realRC
say "It's output was:"
do line over output
say line
end
fsObj~close
'del MyFileName.temp'
Since I do that sort a thing quite often, I just wrote some public routines to handle the sequence. Once you do that it is pretty easy to use.
--
Mark Miesfeld