Exec
- Last UpdatedOct 29, 2026
- 3 minute read
Exec is a built-in function that executes a command as if it were entered using the computer's command-line interface (CLI).
|
Function |
Group |
Execution |
String Exp. |
Windows |
Windows Embedded |
IoT View |
Thin Clients |
Mobile Access |
|---|---|---|---|---|---|---|---|---|
|
Exec |
Module Activity |
Synchronous or Asynchronous |
No |
Supported |
Supported |
Supported |
Supported |
Not supported |
Syntax
Exec(strCommand,optNumState,optNumSync,"optTagReturnOrHandle")
Exec ( strCommand { | , { optNumState | 0 | 1 | 2 | 3 | 4 | 7 } { | , { optNumSync | 0 | 1 } ,"optTagReturnOrHandle" } } )
strCommand
The command to be executed.
Keep in mind that in most cases, a command written to be executed on Windows cannot be executed on Linux, and vice versa.
optNumState
A numeric flag that specifies the initial state of the Windows program (if any) that is run by the command:
|
Value |
Description |
|---|---|
|
0 |
Hide the program and give control to another one. |
|
1 |
Make the program active and display it. |
|
2 |
Make the program active and display it as an icon. |
|
3 |
Make the program active and maximize it. |
|
4 |
Display the program at its most recent size. The program is still active. |
|
7 |
Display the program as an icon. The program is still active. |
This parameter is optional; if no value is specified, the default value is 1.
This parameter is not supported when the project's target platform is Embedded; regardless of which value is specified, the function is executed with the default value.
optNumSync
A numeric flag that specifies whether the command is executed synchronously or asynchronously:
|
Value |
Description |
|---|---|
|
0 |
Execute asynchronously. This function will return immediately. |
|
1 |
Execute synchronously. This function will return when the execution is completed. |
This parameter is optional; if no value is specified, the default value is 0.
optTagReturnOrHandle
The name of a project tag that will receive feedback about the execution of the command:
-
If the command is executed asynchronously, the tag will receive a handle that can used with the ExecIsRunning function to determine whether the command is still being executed.
-
If the command is executed synchronously, the tag will receive the command's exit code. That exit code is separate from this function's own return value.
This parameter is optional, but given its nature, there is no default value.
Note: If this parameter is enclosed in quotes, the string literal will be used. Otherwise, the value of the tag/expression will be used.
Return value
This function returns one of the following possible values:
|
Value |
Description |
|---|---|
|
0 |
Command was not executed successfully. |
|
1 |
Command was executed successfully. |
This return value indicates only whether the execution started successfully, particularly if the command was executed asynchronously. It does not indicate when or how the execution was completed. To determine that, use the ExecIsRunning function.
Examples
Start Notepad, display the program, and then immediately continue to the next line of the script:
Exec("C:\Windows\System32\notepad.exe",4)
Start MS Paint, make the program active, and then immediately continue to the next line of the script:
Exec("C:\Windows\System32\mspaint.exe")
Call an external batch file, execute it synchronously, hide the program, wait until the execution is completed, and then store the exit code in the tag execReturn:
Exec("CMD /C call C:\Temp\MyBatch.bat",0,1,"execReturn")
Call an external VBScript file, execute it asynchronously, hide the program, store the handle in the tag execHandle, and then continue to the next line of the script:
Exec("CMD /C call C:\Temp\MyScript.vbs",0,0,"execHandle")