I think the return code API is a great approach. Different conditions set different values. Just like ERRNO in C.
I don't know if/how it would work with a syntax error like the indent, but that should get weeded out in testing.
Thank you Kevin!
-----Original Message-----
From: OpenSource [mailto:opensource-bounces@xxxxxxxxxxxx] On Behalf Of John Yeung
Sent: Thursday, September 29, 2016 2:56 PM
To: IBMi Open Source Roundtable
Subject: Re: [IBMiOSS] Checking return status of Pyhon program
On Thu, Sep 29, 2016 at 11:47 AM, Roger Harman <roger.harman@xxxxxxxxxxx> wrote:
For example, I made a slight change and had an indentation error. Obvious Python failure but how can I inform the CL?
You seem to be interested in a broad range of error conditions. If you
are talking about getting the "full-blown" feedback for ANY kind of
Python error (in other words, the Python traceback), then I believe
you have no recourse but to do some kind of logging to some kind of
file. This could take the form of just redirecting stdout and/or
stderr, or using Python's logging module (as Jim mentioned), or
something custom. It wouldn't have to be a stream file; Python can
write to database tables, if that makes it easier on the CLP.
If you are just interested in a simple program status (like "success"
or "failure", or perhaps up to a handful of different predetermined
status codes), then the API Kevin mentioned is pretty much tailor-made
for that. (You would have to make sure the Python application is
properly setting the exit code. This isn't a universal or automatic
thing.)
John Y.
As an Amazon Associate we earn from qualifying purchases.