{"record":{"id":"b08d9e534469d64e","repo":"pentaho/pentaho-kettle","slug":"error-opening-new-file","errorCode":null,"errorMessage":"Error opening new file : ","messagePattern":"Error opening new file : ","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/textfileoutputlegacy/TextFileOutputLegacy.java","lineNumber":181,"sourceCode":"        cmdstr = \"command.com /C \" + cmdstr;\n      } else {\n        if ( Const.getOS().startsWith( \"Windows\" ) ) {\n          cmdstr = \"cmd.exe /C \" + cmdstr;\n        }\n      }\n      if ( isDetailed() ) {\n        logDetailed( \"Starting: \" + cmdstr );\n      }\n      Runtime runtime = Runtime.getRuntime();\n      data.cmdProc = runtime.exec( cmdstr, EnvUtil.getEnvironmentVariablesForRuntimeExec() );\n      data.writer = data.cmdProc.getOutputStream();\n\n      StreamLogger stdoutLogger = new StreamLogger( log, data.cmdProc.getInputStream(), \"(stdout)\" );\n      StreamLogger stderrLogger = new StreamLogger( log, data.cmdProc.getErrorStream(), \"(stderr)\" );\n      new Thread( stdoutLogger ).start();\n      new Thread( stderrLogger ).start();\n    } catch ( Exception e ) {\n      throw new KettleException( \"Error opening new file : \" + e.toString() );\n    }\n  }\n}\n\n","sourceCodeStart":163,"sourceCodeEnd":186,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/textfileoutputlegacy/TextFileOutputLegacy.java#L163-L186","documentation":"TextFileOutputLegacy.initCommandStreamWriter() fails to start the external command process (Runtime.exec) that the step writes rows to when 'file as command' is enabled, and wraps the failure in a KettleException. Called from initOutput/writeRowToCommand.","triggerScenarios":"fileAsCommand=true and Runtime.exec(command) throws: command binary not found on PATH, invalid command string with bad quoting/variable substitution, or IOException creating the process. Called from initOutput (step init) or writeRowToCommand (lazy init per row).","commonSituations":"Using shell commands like 'gzip > file.gz' on Windows without cmd.exe; command not installed in the container/PATH; environment variables in the command not resolved.","solutions":["Verify the command exists and is on PATH in the execution environment (which <cmd>).","Check the command string quoting and that variable substitutions (${...}) resolve to valid values.","On Windows wrap shell syntax with cmd /c, on Unix ensure /bin/sh is available.","Read e.toString() appended to the message — it names the actual exec failure (e.g. 'Cannot run program')."],"exampleFix":"// before (command field)\ncat ${Internal.Transformation.Filename} | gzip > out.gz\n// after (use full path / shell wrapper)\n/bin/sh -c \"cat ${Internal.Transformation.Filename} | gzip > out.gz\"","handlingStrategy":"validation","validationCode":"// Before running the transformation, verify the command resolves\nString cmd = environmentSubstitute(commandField);\nString binary = cmd.trim().split(\"\\\\s+\")[0];\nProcess p = new ProcessBuilder(\"which\", binary).redirectErrorStream(true).start();\nif (p.waitFor() != 0) throw new IllegalStateException(\"Command not on PATH: \" + binary);","typeGuard":null,"tryCatchPattern":"try { step.init(); }\ncatch (KettleException e) {\n  log.error(\"Command writer failed to start: {}\", e.getMessage(), e); // message includes e.toString() of exec failure\n}","preventionTips":["Use absolute paths for commands in 'file as command' mode","Test the command manually in the target environment/container","Beware of quoting/substitution in the command string"],"tags":["process-exec","kettle","external-command","io"],"backgroundTag":"command-not-found","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"}