SYS_Execute Function

Action

Executes the specified command.

Syntax

iReturn = SYS_Execute (sCmdLine [, lsOutput], ExecutionMode)
Variable Description
iReturn The return value of the command. INTEGER.
sCmdLine The command to execute. STRING.
lsOutput Optional: A variable to hold any text written to stdout when sCmdLine runs. The contents of lsOutput are ignored when the ExecutionMode is set to EM_CONTINUE_RUNNING. LIST OF STRING.
ExecutionMode Optional: An option specified with one of the constants defined for the EXECUTIONMODE enumerated data type. Defaults to EM_WAIT_UNTIL_FINISHED if not specified.

Notes

  • SYS_Execute executes sCmdLine and returns the exit value returned by the command. Any output is stored in lsOutput; each line of text becomes an item in the list. SYS_Execute modifies the lsOutput variable. Any previous value in lsOutput is discarded.

  • If you are using the Classic Agent, do not use SYS_Execute to execute .reg files; use the Start command instead. SYS_Execute was designed to execute commands that do not require user input and that terminate almost immediately after it has been executed. Silk Test Classic waits for any command that brings up a process requiring user input. For example: SYS_Execute ("freecell.exe") starts Freecell in an invisible window and Silk Test Classic does not continue until the Freecell process is terminated. On the other hand, SYS_Execute("start freecell.exe") starts Freecell in a visible window, and still Silk Test Classic does not continue until the Freecell process is terminated. The Open Agent automatically opens the application process in a visible window and the "start <process.exe>" string is not necessary.

  • If SYS_Execute is targeted for the local host, it is processed by the Silk Test Classic process. Otherwise, SYS_Execute is executed by the agent process, not the Silk Test Classic process. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator.

  • As an alternative to SYS_Execute, you can use the Shell32.dll from Microsoft Windows with the ShellExecuteW() command. Unlike SYS_Execute, ShellExecuteW() returns control to the application after it starts the executable. Or, use APP_Start() from bwcompat.inc, which is provided with Silk Test Classic. For details about APP_Start(), refer to the bwcompat.inc file. For details about ShellExecuteW(), refer to the Windows help.

  • If scripts are blocking during the execution of the SYS_Execute method, and the focus is set on the command executing and not the result of the execution, you can set the ExecutionMode to EM_CONTINUE_RUNNING. In this case the contents of lsOutput are ignored.

Example 1

LIST OF STRING lsDirOut
SYS_Execute("ls", lsDirOut, EM_WAIT_UNTIL_FINISHED)

Example 2

The following code sample creates a directory and copies a file from one directory to another:
[-] testcase Test1() appstate none
	[ ] // creates a directory 'mf_community1'
	[ ] SYS_Execute("mkdir c:\mf_community1")
[ ] 
[-] testcase Test2() appstate none
	[ ] // creates a second directory 'mf_community2'
	[ ] SYS_Execute("mkdir c:\mf_community2")
[ ]  
[-] testcase Test3() appstate none
	[ ] // before running this testcase, create a file in the first directory 'mf_community1' called 'myFilename.txt'
	[ ] 
	[ ] // copy the file test.txt from mf_community1 to mf_community2
	[ ] // the /y parameter is to proceed if the file already exists
	[ ] SYS_Execute("copy c:\mf_community1\myFilename.txt c:\mf_community2 /y")
[ ] 
[-] testcase Test4() appstate none
	[ ] // remove directories and files in the specified directory in addition to the directory itself
	[ ] SYS_Execute("rmdir c:\mf_community1 /s /q")
	[ ] SYS_Execute("rmdir c:\mf_community2 /s /q")