none
status and program exit code RRS feed

  • Question

  • We have runbooks using run program activity, that is using command execution, the path is .bat file on a remote windows server. The bat file calls a powershell command, which in turn calls a sqlplus script.

    What we found is run program activity always return successful and goes to next step even there is an error in the run program activity. So i start to use the program exit code to evaluate if it is a 0  or 1, but still it always return 0 and goes to next step.

    In the command line .bat file we do use :

     

    powershell -c D:\mypsscript.ps1 -sqlFileToExecute  'D:\mysqlscript.sql' -outputFile './myfile.csv' -destOutputPath 'D:\mypath' -logFilePath 'D:\Logs' -logFile 'mylogfile.log'
    exit /b %errorlevel%

    And in the SQL script we do use 

    --
    whenever sqlerror exit sql.sqlcode

    I intentionally put a wrong path in the powershell command above, the log tells the SP2-0310: unable to open file ..

    But the run program still pass program exit code =0 and goes to next step.

    What am I missing?

    Thanks


    Thanks

    Monday, September 16, 2019 5:50 PM

All replies

  • Hi,

    The Run Program activity cannot know what is going on inside a script, it will only return success (exit code 0) or failed (exit code 1) if the script was successfully called or not.

    Example:

    If Run Program cannot call the script or if it cannot reach the path of the script it will fail with an error code of 1.

    In your case, if you would intentionally fail the path of the mypsscript.ps1 script to an invalid path, the Run Program would return 1.

    powershell -c D:\mypsscript.ps1 -sqlFileToExecute  'D:\mysqlscript.sql' -outputFile './myfile.csv' -destOutputPath 'D:\mypath' -logFilePath 'D:\Logs' -logFile 'mylogfile.log'
    exit /b %errorlevel%

    As long as the path to the script is OK, the Run Program will return success (exit code 0).

    Best regards,
    Leon


    Blog: https://thesystemcenterblog.com LinkedIn:

    Monday, September 16, 2019 6:51 PM