After some trial and error I discovered that my check whether the sys.argv
list was empty was failing. I had been trying this
if not sys.argv
which I expected to work in the case where I was running from ExecuteScript
rather than the linux command line. In the case running from the command
line, I knew with certainty that I would have at a minimum the scrpt.py in
the list of sys.argv.
It turns out that when executing the script from the ExecuteScript
processor, the script.py is not in the sys.argv. But sys.argv does not
evaluate to empty - it evaluates to [''].
When I check with this
if str(sys.argv) == '[\'\']'
the logic works as needed.
I feel like I don't fully understand what's going on, but I do have it
working. Seems to me that the "if not sys.argv" should have worked, but it
does not. I think when I try str(sys.argv) I may force the two single quote
literals into the list, maybe? I am not sure why the "not sys.argv" failed.
In any case, I have something that works and wanted to circle back and post
what I found.
On Sun, Feb 18, 2018 at 7:54 PM, Matt Burgess <mattyb...@apache.org> wrote:
> I don't think that's possible because I don't think the user-defined
> properties are guaranteed to be in a particular order (insertion order
> in the processor config dialog, e.g.), but someone please correct me
> if I'm wrong. If true, then we wouldn't be able to have the
> user-defined properties set deterministically as "positional"
> arguments in an array.
> You might be able to check to see if sys.argvs is defined  or None
> or empty, and if so, then try the user-defined properties as variables
> using the same technique. You wouldn't be able to support a "usage()"
> type of thing (where in a command-line script you print the usage if
> the arguments are not valid/complete), but you should be able to
> determine whether the script is being run from the command-line Python
> or from ExecuteScript Jython.
>  https://stackoverflow.com/questions/1592565/determine-
> On Sun, Feb 18, 2018 at 10:25 AM, James McMahon <jsmcmah...@gmail.com>
> > Checking back in. Can we reference the user-defined custom config parms
> > passed in from ExecuteScript as sys.argvs in the python script being
> > executed by ExecuteScript?
> > On Fri, Feb 16, 2018 at 1:14 PM, James McMahon <jsmcmah...@gmail.com>
> >> Good afternoon. I have a python script I would like to run from
> >> ExecuteScript. Since my script can run from either a command line in
> >> mode or from the ES processor, I'd like to set up initial logic to
> >> which command line parms i have, and direct actions in the script
> >> accordingly.
> >> At the command line I'll execute like this: myScript.py
> >> [loggingOutput as either of NIFI | SCRIPT] - two arguments.
> >> From Matt B's helpful post here...
> >> https://community.hortonworks.com/articles/77739/
> >> ...I know that I can feed the script these arguments from ExecuteScript
> >> creating two new properties within ExecuteScript and setting their
> >> In the script I can read those into the script like this:
> >> configFile = configFile_nifi.getValue()
> >> targetOutput = loggingOutput.getValue()
> >> But i need to read these arguments in one way if they are from the
> >> line, and using the above syntax if they are from the ExecuteScript
> call of
> >> the script. If set by the NiFi ES processor, can i refer to these parms
> >> len(sys.argv), sys.argv, and sys.argv?
> >> If not, how can I direct the setting of my script variables based on
> >> whether the arguments come from the command line or from the NiFi
> >> configuration?
> >> Jim