January 25, 2010

Running DOS Commands from a QA Wizard Pro Script

Helix ALM
You can use the RunCommand statement in a QA Wizard Pro script to launch a DOS command from the Windows command line. The information required for a RunCommand statement includes:
  • Executable path
  • Working directory
  • Command line arguments
The executable is cmd.exe, which is located in C:WINDOWSsystem32. The working directory can be any location you choose. The command line arguments is a string containing the command you wish to execute and any needed parameters or flags. When creating the argument string:
  • You must enclose the DOS command and arguments in quotes, using the escape character (i.e., "dir *.doc ")
  • You must escape the backslash character in any path specification (i.e., "C:\WINDOWS\system32\cmd.exe")
  • You must use the '/C' flag to force the command window to close upon completion
  • You must enclose the entire command line argument string in quotes (i.e., "/C"dir *.doc "")
For example, the following script step will copy file1.txt to file2.txt in the C:Output directory:
          RunCommand("C:\WINDOWS\system32\cmd.exe", "C:\Output", "/C"copy file1.txt file2.txt"")
The working directory will be used for redirection unless otherwise specified in the command line arguments. This will list the contents of the C:Test directory in the file C:My Fileslist.txt:
          RunCommand("C:\WINDOWS\system32\cmd.exe", "C:\Output", "/C"dir C:\Test > C:\My Files\list.txt"")
Since the RunCommand statement returns '0' if successful or '1' otherwise, you can branch on the result of the statement:
          If RunCommand("C:\WINDOWS\system32\cmd.exe", "", "/C"dir > C:\data.txt"") = 1 Then
              Println("File not found!")
          End If