1

I am executing my job via PowerShell script however the kitchen exit return code doesn't seem to work... Based on documentation that I read below is the return codes for kitchen

  • 0 = The job/transformation ran without a problem.

  • 1 = An error occurred during processing.

  • 2 = An unexpected error occurred during loading/running of the job/transformation. Basically, it can be an error in the XML format, an error in reading the file, or it can denote that there are problems with the repository connection.

  • 3 = Unable to connect to a database, open a file, or other initialization errors.

  • 7 = The job/transformation couldn't be loaded from XML or the repository; basically, it could be that one of the plugins in the plugins/ folder is not written correctly or is incompatible.

  • 8 = An error occurred while loading steps or plugins (an error in loading one of the plugins mostly).

  • 9 = Command line usage printing.

     $FilePath = 'C:\pdi-ce-8.1.0.0-371\data-integration\kitchen.bat'
     $ArgumentList = '-file=C:\pdi_debug\debug.kjb -level=MINIMAL >> 
     C:\pdi_debug\bat.log'
     $PDIProcess = Start-Process -Filepath $FilePath -ArgumentList 
     $ArgumentList -Wait -PassThru
     Write-host "The Exit code from Kitchen is " $LastExitCode
    
     If($LastExitCode  -eq 0) #This doesn't seem to correctly get the exit 
      code we are wanting :-/
      {
       $EMAIL_SUBJECT='INT: Pentaho_J_load SUCCEEDED'
      }
     Else
      {
        $EMAIL_SUBJECT='INT: Pentaho_J_load FAILED'
    
Shawn
  • 45
  • 1
  • 9

1 Answers1

3
  • To synchronously execute console applications or batch files and capture their output / check their exit code, call them directly (c:\path\to\some.exe ... or & $exePath ...), do not use Start-Process - see this answer.

    • When Start-Process is used, the only way to get the process exit code is via the process-information object (of type [System.Diagnostics.Process]) returned by the -PassThru switch and its .ExitCode property (with -Wait, this property is instantly accessible; without it, .WaitForExit() must be used, or polling of the .HasExited property).

    • By contrast, the automatic $LASTEXITCODE variable is only ever set after direct invocation of an external program (by invoking it directly or - if the path needs quoting and/or involves variable references - via &, the call operator).

Therefore, invoke your batch file directly, and check $LASTEXITCODE afterwards:

C:\pdi-ce-8.1.0.0-371\data-integration\kitchen.bat -file=C:\pdi_debug\debug.kjb -level=MINIMAL >> C:\pdi_debug\bat.log

Note: This will make PowerShell append to (>>) to file C:\pdi_debug\bat.log, which means that invariably[1] the following character encoding is used:

  • in Windows PowerShell: "Unicode" (UTF-16LE)
  • in PowerShell (Core) (v6+): BOM-less UTF-8

If you need cmd.exe to perform the appending, call the batch file via cmd /c instead:

cmd /c 'C:\pdi-ce-8.1.0.0-371\data-integration\kitchen.bat -file=C:\pdi_debug\debug.kjb -level=MINIMAL >> C:\pdi_debug\bat.log'

Note: Due to quirks in how cmd.exe relays exit codes set by batch files when called from outside cmd.exe the most robust way to invoke batch files is to use cmd /c and to append & exit to the command string - see this answer.


[1] In PowerShell versions 5.1 and above, it is possible to control the default encoding used by > / >>, albeit in a non-obvious way: see this answer.

mklement0
  • 382,024
  • 64
  • 607
  • 775