Skip to main content

Action: ExecuteExternalCommand

Function: The action starts a process (application, batch script, etc.) outside of CODESYS and captures its output and exit code.

Call: System test driver

In general, the behavior of the action depends on the Only start and Check of the previous process from the input parameter options. The following cases are possible:

  • The Only start and Check of the previous process from the input parameter options are disabled. This is used for starting a process synchronously and waiting for it to end. The test script is paused during this time.

  • Only the Only start option is enabled. This is used for starting a process asynchronously and later querying its result in the test script. The context of the process is stored in a variable.

  • Only the Check of the previous process from the input parameter option is enabled. This is used for querying the result of a process started asynchronously from its saved context.

Tab: Configuration

Table 73. Command

Executable file

Name of the process which is started

Example: cmd

Requirement: The Check of the previous process from the input parameter option is disabled.

Arguments

Command-line arguments

Optional

Example: /c calc.exe

Requirement: The Check of the previous process from the input parameter option is disabled.

Working directory

Working directory of the process

Optional

Requirement: The Check of the previous process from the input parameter option is disabled.

Only start

standard icon

  • The Executable file is started.

  • The Save process in output parameter (leave blank to ignore) and Delay [ms] fields are enabled.

  • The Check of the previous process from the input parameter, Wait for exit [ms], Exit code, and Save stdout to fields are disabled.

Requirement: The Check of the previous process from the input parameter option is disabled.

Save process in output parameter (leave blank to ignore)

Output Parameters

Specified without quotation marks

Example: {ProcessExe}

The execution context of the process is stored in this output parameter. If the Check of the previous process from the input parameter option is enabled when the command is executed later, then this output parameter can be evaluated.

Optional

Requirement: The Only start option is enabled.



Check of the previous process from the input parameter

standard icon

  • The fields from the Command area are disabled.

  • The name of an input parameter has to be specified in the input field after Check of the previous process from the input parameter. This has to refer to a process context which was previously saved using the Save process in output parameter option.

  • The configuration options in the Result area refer to the process context which is read from the input parameter.

Table 74. Result

Wait for exit [ms]

Number of milliseconds to wait for the process to end

If the external process takes longer than this time limit, then the action fails.

If no value is entered here, then there is no time limit and the action may wait indefinitely.

Requirement: The Only start option is disabled.

Delay [ms]

Time span for the action to wait before it returns

If no value is entered here, then the action returns immediately after starting the process without waiting for the process to end.

Requirement: The Only start option is enabled.

Exit code

Checks the exit code of the process

If the code does not match, then the action fails.

If the field is left blank, then there is no check of the exit code.

Requirement: The Only start option is disabled.

Save stdout to

Name of the output parameter

Specified without quotation marks

Example: {ExternalOutputStream}

When a valid parameter name is specified, the action saves the default output stream of the external process to the specified output parameter.

Requirement: The Only start option is disabled.

Check result from stdout

standard icon: The output of the process is compared with the contents of Result conforms field for consistency. If there is no match, then the action fails. If the Contain mode option is also enabled, then the system simply compares whether or not the contents of the input field are contained in the output stream of the process instead of a match.

Requirement: The Only start option is disabled.

Contain mode

standard icon: The contents of Result conforms are checked to see whether or not they are contained in the output stream of the process.

Requirement: The Check result from stdout option is enabled.

Result conforms

Input field

When the Check result from stdout or Contain mode options are enabled, the contents are compared with the output stream of the process.

Requirement: The Check result from stdout option is enabled.



Tab: Parameters

The parameters defined on the Parameters tab are used to exchange values between test script variables and parameters of test actions. Parameters can be used as placeholders on the Configuration tab. For this, the name of the parameter is set in braces in the configuration dialog. Example: {name}.

Tip

Variables defined globally in the script (with the prefix $GLOBALS.) can be used directly in the test action. It is not necessary to use input parameters for passing. Using output parameters is necessary for writing global variables.

Input parameters: When executing the test action, the values of the test script variables are passed to the input parameters of the test action and can be used in the configuration of the test action.

Output parameters: When executing the test action, the values of the output parameters of the test action are passed to the test script variables and can be used (for example, in other test actions).

Name

Name of the input/output parameter

This name is defined in addition to the variable name to identify the origin of the parameter when it is passed to another script. During the test run, this name is displayed as the Outer name on the Variables (scope #<n>) tab in the Test progress window.

Background: When a script A calls another script B, and its variable x passes y as a parameter to the script B, then the parameter y is the variable y from the point of view of script B.

To see that this variable is recognized as variable x "outside" of script B, there is the Name column ("Outer name"). The variable y has the name x in the scope pf script B because it has been passed as variable x to the parameter y in the scope of the calling script A.

Variable

Name of the test script variable

Example: TS_CaseA_Result

Move Up

Moves the selected variable one line up

Move Down

Moves the selected variable one line down

Remove

Removes the selected variable from the list