Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to handle failure of NiFi ExecuteProcess processor while it doesn't have a failure relationship

avatar
Contributor

I am trying to execute a job by the use of ExecuteProcess processor to run the shell command that executes this job.

But if the shell command failed, the error messages only appear in the log (at the top right of the processor) but the processor doesn't have a failure relationship. I want to handle the case of failure to do some action or send emails.

1 ACCEPTED SOLUTION

avatar
Master Guru

You may be better served with ExecuteStreamCommand rather than ExecuteProcess for this case. You could schedule a GenerateFlowFile at the same rate your ExecuteProcess was scheduled for, and set Ignore STDIN to true in ExecuteStreamCommand. Then the outgoing flow files will have the execution.status attribute set, which you can use with RouteOnAttribute to handle failures (non-zero exit codes, e.g.)

If you must use ExecuteProcess, perhaps you could run your shell command followed by a double-bar and a command that prints something you can check for later, such as:

myCommand || echo "!ERROR!"

I haven't tried this so I don't know if that would work, but if it does it would allow you to use RouteOnContent to check for that error string to indicate failure. The same technique works without the || if you know what to look for in your failed command output.

View solution in original post

2 REPLIES 2

avatar
Master Guru

You may be better served with ExecuteStreamCommand rather than ExecuteProcess for this case. You could schedule a GenerateFlowFile at the same rate your ExecuteProcess was scheduled for, and set Ignore STDIN to true in ExecuteStreamCommand. Then the outgoing flow files will have the execution.status attribute set, which you can use with RouteOnAttribute to handle failures (non-zero exit codes, e.g.)

If you must use ExecuteProcess, perhaps you could run your shell command followed by a double-bar and a command that prints something you can check for later, such as:

myCommand || echo "!ERROR!"

I haven't tried this so I don't know if that would work, but if it does it would allow you to use RouteOnContent to check for that error string to indicate failure. The same technique works without the || if you know what to look for in your failed command output.

avatar
Contributor

The first solution works! Thanks @Matt Burgess

Here's the RouteOnAttribute configurations.

38543-screenshot-from-2017-09-06-17-29-33.png