{"record":{"id":"83316a72efc6c495","repo":"flowable/flowable-engine","slug":"could-not-execute-shell-command-for-execution","errorCode":null,"errorMessage":"Could not execute shell command for + execution","messagePattern":"Could not execute shell command for \\+ execution","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/behavior/ShellActivityBehavior.java","lineNumber":137,"sourceCode":"\r\n            Process process = processBuilder.start();\r\n\r\n            if (waitFlag) {\r\n                int errorCode = process.waitFor();\r\n\r\n                if (resultVariableStr != null) {\r\n                    String result = convertStreamToStr(process.getInputStream());\r\n                    execution.setVariable(resultVariableStr, result);\r\n                }\r\n\r\n                if (errorCodeVariableStr != null) {\r\n                    execution.setVariable(errorCodeVariableStr, Integer.toString(errorCode));\r\n\r\n                }\r\n\r\n            }\r\n        } catch (Exception e) {\r\n            throw new FlowableException(\"Could not execute shell command for \" + execution, e);\r\n        }\r\n\r\n        leave(execution);\r\n    }\r\n\r\n    public static String convertStreamToStr(InputStream is) throws IOException {\r\n\r\n        if (is != null) {\r\n            Writer writer = new StringWriter();\r\n\r\n            char[] buffer = new char[1024];\r\n            try (Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {\r\n                int n;\r\n                while ((n = reader.read(buffer)) != -1) {\r\n                    writer.write(buffer, 0, n);\r\n                }\r\n            }\r\n            return writer.toString();\r","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/behavior/ShellActivityBehavior.java#L119-L155","documentation":"Flowable's ShellActivityBehavior runs an external shell command from a BPMN service task and writes the exit code to an optional result variable. Any exception while creating or executing the process (bad command path, IO problems, interrupted waits) is wrapped in this FlowableException, keeping the original as the cause. It signals the shell invocation itself failed, not a business-logic error.","triggerScenarios":"Shell task configured with a command/executable that does not exist or is not on PATH; working directory missing; argument array invalid; IO streams fail; Runtime.exec throws; reading output or writing the error-code variable throws.","commonSituations":"Deploying processes that run 'sh script.sh' where the script was never deployed to the server; container images without the required binary; permission errors on the executable; arguments containing spaces due to misconfigured expression results.","solutions":["Verify the shell command/executable exists and is executable on the machine running the Flowable engine (or in the container image)","Inspect the wrapped cause exception (getCause()) for the exact OS-level failure","Log/validate the command and arguments by reading ShellActivityBehavior fields before deployment; test the exact command manually as the engine's OS user","Set the extension attributes (command, args, wait, outputVariable, errorCodeVariable) correctly in the BPMN XML","If the process should not be killed by a failing command, add an error boundary event on the shell service task"],"exampleFix":"// before\n<flowable:field name=\"command\" stringValue=\"my-script.sh\" />\n// after\n<flowable:field name=\"command\" stringValue=\"/opt/scripts/my-script.sh\" />","handlingStrategy":"try-catch","validationCode":"File script = new File(commandPath);\nif (!script.exists() || !script.canExecute()) {\n    throw new IllegalStateException(\"Shell command not executable: \" + commandPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n    execution.setVariable(\"result\", runShell(...));\n} catch (FlowableException e) {\n    logger.error(\"Shell command failed\", e.getCause());\n    throw new BpmnError(\"SHELL_FAILED\", e.getCause().getMessage());\n}","preventionTips":["Bake required binaries/scripts into the container image or deploy target","Test the exact command as the engine's OS user before deployment","Use absolute paths instead of PATH lookups","Add an error boundary event to the shell task"],"tags":["shell","bpmn","service-task","process-execution"],"backgroundTag":"command-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}