{"record":{"id":"d2aab04cf542e10f","repo":"pentaho/pentaho-kettle","slug":"process-stderr-stdout-output-on-non-zero-exit-status","errorCode":null,"errorMessage":"process stderr/stdout output on non-zero exit status","messagePattern":"process stderr/stdout output on non-zero exit status","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/execprocess/ExecProcess.java","lineNumber":148,"sourceCode":"        for ( int i = 0; i < data.indexOfArguments.length; i++ ) {\n          // Runtime.exec will fail on null array elements\n          // Convert to an empty string if value is null\n          String argString = data.previousRowMeta.getString( r, data.indexOfArguments[i] );\n          cmdArray.add( Const.NVL( argString, \"\" ) );\n        }\n\n        execProcess( cmdArray.toArray( new String[0] ), processResult );\n      } else {\n        execProcess( processString, processResult );\n      }\n\n      if ( meta.isFailWhenNotSuccess() ) {\n        if ( processResult.getExistStatus() != 0 ) {\n          String errorString = processResult.getErrorStream();\n          if ( Utils.isEmpty( errorString ) ) {\n            errorString = processResult.getOutputStream();\n          }\n          throw new KettleException( errorString );\n        }\n      }\n\n      // Add result field to input stream\n      int rowIndex = data.NrPrevFields;\n      outputRow[rowIndex++] = processResult.getOutputStream();\n\n      // Add result field to input stream\n      outputRow[rowIndex++] = processResult.getErrorStream();\n\n      // Add result field to input stream\n      outputRow[rowIndex++] = processResult.getExistStatus();\n\n      // add new values to the row.\n      putRow( data.outputRowMeta, outputRow ); // copy row to output rowset(s);\n\n      if ( log.isRowLevel() ) {\n        logRowlevel( BaseMessages.getString( PKG, \"ExecProcess.LineNumber\", getLinesRead()","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/execprocess/ExecProcess.java#L130-L166","documentation":"With 'fail when not success' enabled, a non-zero exit code from the spawned process makes ExecProcess throw with the process's stderr (or stdout if stderr is empty) as the message. The step surfaces the child process's own output as the Kettle error.","triggerScenarios":"processRow, per row: processResult.getExistStatus() != 0 and meta.isFailWhenNotSuccess() is true — e.g. the command is missing (exit 127), has bad arguments (exit 1-2), or returns failure for that row's input.","commonSituations":"Command path not on PATH; wrong arguments built from row fields; script exits non-zero for expected conditions (file not found); Windows vs Unix shell differences; permissions on the executable.","solutions":["Read the exception message (the process's stderr/stdout) to see why the command failed.","Verify the command and arguments for that specific row are correct (log processString and argument fields).","Uncheck 'Fail when not success' if non-zero exits are acceptable, and inspect the result field instead.","Fix the external command/environment (PATH, permissions, script bugs)."],"exampleFix":"// before: step configured to fail on any non-zero exit\nmeta.setFailWhenNotSuccess(true);\n// after: tolerate and inspect exit status via the result field\nmeta.setFailWhenNotSuccess(false);\n// then branch on the exit-status/result field downstream","handlingStrategy":"try-catch","validationCode":"// test the command manually with the same arguments first\n// e.g. /opt/scripts/myscript.sh arg1 arg2 ; echo $?","typeGuard":null,"tryCatchPattern":"try { rowListener/processRow output } catch (KettleException e) { log.error(\"Process failed: \" + e.getMessage()); /* message is the child's stderr/stdout */ }","preventionTips":["Dry-run the external command with representative arguments","Log the exit status/result field when not failing on error","Keep commands and their environment consistent across hosts"],"tags":["process-execution","exit-code","shell","execprocess"],"backgroundTag":"http-error-response","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}