runShell - noetl/noetl GitHub Wiki

E.g. exitCode = runShell("task1", "step1", "201501")

Parameters

  • task: task name
  • step: step name
  • cur: cursor

Key Variables

  • exitCode: keeps track of the success (0) or failure (1) of a step
  • curDatatype: cursor datatype (date or integer)
  • dateFormat: cursor's date format (e.g. %Y%m); if cursor is an integer: CONF_NOT_FOUND
  • execLists: cursor's command lists
  • cmdList: command from the command lists
  • cmd: concatenated cmdList

Functionality

RunShell loops through the execLists, which is a list of the step's command lists. For each command list (cmdList), runShell joins the cmdList into a single command, and passes the joined command, the current cursor, the cursor datatype, and the dateFormat into curPattern to replace all variable patterns in the command with the cursor. If the testIt boolean is False, then runShell calls subprocess.call on the command, running the command through the command line API. The exitCode is set equal to the return value of the subprocess.call. If testIt is True, then the exitCode is set to 0 (success). The exitCode is then returned.

Except Statement

If an error arises, the except block writes to the log file, recording the time, the command, the cursor value, the exit code, and the error message.

The exitCode is set equal to 1, indicating a failure.

Return Value

RunShell returns the exitCode (0 for success, 1 for failure).