On Thu, Mar 19, 2015 at 11:48 AM, Roger Harman <roger.harman@xxxxxxxxxxx> wrote:
And, I'll give a +9999 to Rob's "loving suggestion". Relying on parsing printed output is a fools game.
It's a game that is often played by fools, but not everyone who plays is a fool.
I once had a commercial package start failing a particular process after an OS upgrade. As I recall, they were looking at WRKDSKSTS *PRINT output to determine if an operation could run. When the spool file changed - kaboom - task failed every time.
Without looking at their code, I would have to guess that they just
wrote it badly. Now, I'm not advocating putting spool-parsers into
commercial packages if you can help it! I mean, if this is being
released to the public, and to the *paying* public no less, then
absolutely use an API if there's one available.
But I have seen APIs break from version to version too. And if your
code relies on it, then it's REALLY broken. When you're parsing text
robustly, it's OK if columns move a little here or there. If you're
doing it really robustly, it's even OK if the order of the columns
changes. Try shuffling the order of parameters in an API and see if
there's ANYTHING you can do to cope with that.
Let me be clear: Usually it's more reliable to use APIs. Further, most
spool-parsers are frankly not well written.
In part, it's because they usually don't have to be. They may be
ad-hoc. But also, in part it's because most IBM i programmers (and
especially AS/400 programmers!) either don't have or don't know about
better techniques and tools. If your tool is CL, yeah, your spool
parser is going to suck. If you are using RPG, then it *may* be
decent, but most likely will also suck. The effort required to write a
really robust spool parser in RPG is higher than the effort to just
get the API calls right already. And yes, even with the absolute
slickest and most bullet-proof text parsing in the world, the spooled
output of a command could still change radically enough to break it.
So I *do* recommend using APIs over spool-parsing. But I hope people
aren't dismissive of something just because they heard someone tell
them a rule against it. I hope people understand what *actually* makes
something a bad idea, and not confuse incidental or contributing
factors with intrinsic ones.
John
As an Amazon Associate we earn from qualifying purchases.