ExecuteCommand('Trigger',"'Command'","'Arguments'","'UserName'","'Password'",'Timeout=0')
Arguments
|
'Trigger' |
Binary signal or expression as a trigger for the execution of the command |
|
"'Command'" |
Full and absolute path to the command (.exe, .bat etc.) that should be executed |
|
"'Arguments'" |
Arguments/parameters required to execute the command |
|
"'UserName'" |
Username of an account which has the permission to execute "'Command'". |
|
"'Password'" |
The password, related to the user name |
|
'Timeout' |
Optional parameter; if specified and >0, the execution will be aborted as soon as 'Timeout' [s] has expired. |
Description
This function executes the "'Command'" "'Arguments'" command line for a rising edge of 'Trigger'. The return value is 1 (TRUE) while the invoked process is running. Thus, this function is to used as expression for digital signals. Other rising edges are ignored as long as the process is running.
The full, absolute path for the executable file must be specified for "'Command'", relative to the ibaPDA server.
If ‘Timeout’ is not specified, the command execution is not aborted and can run endlessly. If a value larger than zero is specified for ‘Timeout’, the execution of the command is aborted if it is not finished by ‘Timeout’ seconds.
The specification of username ("'UserName'") and password ("'Password'") is required for using this function. For security reasons the executables and programs called by this function must run under a dedicated user account. The account specified by "'UserName'" and "'Password'" must have the permission to execute the specified command.
When entering argument, username and password you can use the text encryption feature to obfuscate this information. The text encryption feature is offered as soon as you start to enter text between quotation marks ("…").
Note |
|
|---|---|
|
If you use this function to call programs which generally have a user interface (GUI), then the GUI is not visible. Because the started program runs in the services session without an associated desktop, it is listed in the task manager, but it’s GUI is missing. |
|
Example 1
Computer shutdown
Task description
Depending on a signal from the system control due to switching to an uninterrupted power supply (USP) during a power outage, the ibaPDA computer should be shut down.
Solution
The "shutdown" command from the Windows Command Shell is used to shutdown the computer. A batch file is used because multiple commands, such as stopping the ibaPDA service, are required.
ExecuteCommand([4.14], "D:\Schulung\ibaPDA_ExecuteCommand\Shutdown_PC.bat","","MyUsername","MyPassword")
-
[4.17]: Digital trigger signal to execute the command -
D:\training\ibaPDA_ExecuteCommand\Shutdown_PC.bat: Program path for the batch file -
MyUsernameandMyPassword: Specifications for user account
Contents of the Shutdown_PC.bat batch file:
|
1 2 3 4 |
SETLOCAL sc stop ibaPDAService shutdown /f /s /t 10 ENDLOCAL |
Example 2
Starting a batch file, which creates a text file with up-to-date content.
Task description
On a rising edge of a digital signal an actual counter value should be written
Solution
ExecuteCommand([3.17],"c:\tmp\work.bat", GenerateText("Items_%1"), "MyUserName","MyPassword",0)
-
[3.17]: Digital trigger signal to execute the command -
c:\tmp\work.bat: Program path for the batch file to be executedwork.bat; specifiying a batch file is like using a command.Contents of the batch file (example):
-
GenerateText("Items_%1"): Argument for the batch file; the result of this expression (generating a string with counter value) is put into the text filedummy.txtas parameter %1 of the batch file.Contents of the text filedummy.txt(example, dynamic content highlighted in yellow):
-
MyUserName, MyPassword: Login credentials of the user account -
0: Value for timeout, i.e. the execution is not aborted.