pentaho/pentaho-kettle · error · KettleException

Error opening new file :

Error message

Error opening new file : 

What it means

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.

Solutions

  1. Verify the command exists and is on PATH in the execution environment (which <cmd>).
  2. Check the command string quoting and that variable substitutions (${...}) resolve to valid values.
  3. On Windows wrap shell syntax with cmd /c, on Unix ensure /bin/sh is available.
  4. Read e.toString() appended to the message — it names the actual exec failure (e.g. 'Cannot run program').

Example fix

// before (command field)
cat ${Internal.Transformation.Filename} | gzip > out.gz
// after (use full path / shell wrapper)
/bin/sh -c "cat ${Internal.Transformation.Filename} | gzip > out.gz"
Defensive patterns

Strategy: validation

Validate before calling

// Before running the transformation, verify the command resolves
String cmd = environmentSubstitute(commandField);
String binary = cmd.trim().split("\\s+")[0];
Process p = new ProcessBuilder("which", binary).redirectErrorStream(true).start();
if (p.waitFor() != 0) throw new IllegalStateException("Command not on PATH: " + binary);

Try / catch

try { step.init(); }
catch (KettleException e) {
  log.error("Command writer failed to start: {}", e.getMessage(), e); // message includes e.toString() of exec failure
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/b08d9e534469d64e. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/textfileoutputlegacy/TextFileOutputLegacy.java:181

        cmdstr = "command.com /C " + cmdstr;
      } else {
        if ( Const.getOS().startsWith( "Windows" ) ) {
          cmdstr = "cmd.exe /C " + cmdstr;
        }
      }
      if ( isDetailed() ) {
        logDetailed( "Starting: " + cmdstr );
      }
      Runtime runtime = Runtime.getRuntime();
      data.cmdProc = runtime.exec( cmdstr, EnvUtil.getEnvironmentVariablesForRuntimeExec() );
      data.writer = data.cmdProc.getOutputStream();

      StreamLogger stdoutLogger = new StreamLogger( log, data.cmdProc.getInputStream(), "(stdout)" );
      StreamLogger stderrLogger = new StreamLogger( log, data.cmdProc.getErrorStream(), "(stderr)" );
      new Thread( stdoutLogger ).start();
      new Thread( stderrLogger ).start();
    } catch ( Exception e ) {
      throw new KettleException( "Error opening new file : " + e.toString() );
    }
  }
}

View on GitHub (pinned to f3058517a1)