diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java index c0d3f2b4c5..cdaec8f58d 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java @@ -82,7 +82,7 @@ public class ExecuteProcess extends AbstractProcessor { .name("Command Arguments") .description("The arguments to supply to the executable delimited by white space. White space can be escaped by enclosing it in double-quotes.") .required(false) - .expressionLanguageSupported(false) + .expressionLanguageSupported(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); @@ -276,8 +276,10 @@ public class ExecuteProcess extends AbstractProcessor { protected List createCommandStrings(final ProcessContext context) { final String command = context.getProperty(COMMAND).getValue(); - final List args = ArgumentUtils.splitArgs(context.getProperty(COMMAND_ARGUMENTS).getValue(), - context.getProperty(ARG_DELIMITER).getValue().charAt(0)); + final String arguments = context.getProperty(COMMAND_ARGUMENTS).isSet() + ? context.getProperty(COMMAND_ARGUMENTS).evaluateAttributeExpressions().getValue() + : null; + final List args = ArgumentUtils.splitArgs(arguments, context.getProperty(ARG_DELIMITER).getValue().charAt(0)); final List commandStrings = new ArrayList<>(args.size() + 1); commandStrings.add(command); diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java index 59bc575d97..a5d965a73a 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java @@ -268,6 +268,31 @@ public class TestExecuteProcess { assertEquals(1, succeeded.size()); } + @Test + public void testRedirectErrorStreamWithExpressions() { + final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class); + runner.setProperty(ExecuteProcess.COMMAND, "ls"); + runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "${literal('does-not-exist'):toUpper()}"); + runner.setProperty(ExecuteProcess.REDIRECT_ERROR_STREAM, "true"); + + ProcessContext processContext = runner.getProcessContext(); + + ExecuteProcess processor = (ExecuteProcess) runner.getProcessor(); + processor.updateScheduledTrue(); + processor.setupExecutor(processContext); + + processor.onTrigger(processContext, runner.getProcessSessionFactory()); + + if (isCommandFailed(runner)) return; + + final List warnMessages = runner.getLogger().getWarnMessages(); + assertEquals("If redirect error stream is true " + + "the output should be sent as a content of flow-file.", 0, warnMessages.size()); + final List succeeded = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS); + assertEquals(1, succeeded.size()); + assertTrue(new String(succeeded.get(0).toByteArray()).contains("DOES-NOT-EXIST")); + } + /** * On some environment, the test command immediately fail with an IOException * because of the native UnixProcess.init method implementation difference.