Passing command line options in a WiseScript executable

Article:HOWTO4341  |  Created: 2006-07-20  |  Updated: 2006-07-31  |  Article URL http://www.symantec.com/docs/HOWTO4341
Article Type
How To



Question
How do I pass command line options into Wisescript executable?

Answer
Many times when working with an installation or support script, you might want to use the command line to customize the execution of the .EXE. WiseScript lets you do just that via a built-in variable called CMDLINE. This article outlines how you can make use of CMDLINE, access portions of text, and avoid common pitfalls.

WiseScript’s CMDLINE variable stores the text of everything passed on the command line immediately following the .EXE’s file name. There are certain advantages and disadvantages to storing the command line. Methods for working with information stored in this variable change depending on which command line options your installation requires.

The CMDLINE variable contains the complete textual string passed on the command line immediately following the name of your .EXE file. In the sample that follows, you are going to use a sample SETUP.EXE program to see what will end up inside the CMDLINE variable and how to access its information.

For this example, look at the command line that follows:

C:\SETUP.EXE /F /q “C:\Test Folder\test_file.dat”

Normally, the Operating System parses the command line and executes the program SETUP.EXE the following way:

.EXE Path

Option 1

Option 2

Option 3

C:\SETUP.EXE

/F

/q

C:\Test Folder\test_file.dat

While this method makes logical sense and is used by most applications when executing command line options, there are some disadvantages with this method. First, this method places proper formatting of the command line switches in the user’s hands and can be quite unforgiving if a user does not enclose space containing paths in quotation marks. If the user left out the quotations, the command line path would instead look like this:

.EXE Path

Option 1

Option 2

Option 3

Option 4

C:\SETUP.EXE

/F

/q

C:\Test

Folder\test_file.dat



The second disadvantage is that ordering is vitally important. In the previous example, if you look for the /q option, then you need to look at each individual command line section until you find that command. If you need to ensure the user also provides a path to a .DAT file after using the /q option, then either check the next command line section and assume that the .DAT file is there, or begin searching each section of the command line until you locate the data, which could be quite time consuming.

WiseScript takes a different approach to storing the command line options passed to the .EXE. WiseScript stores the entire contents of the command line, including all spaces and quotes into a single variable called CMDLINE. The installation developer is free to parse the command line contents using whatever method best suits their installation methodology. This article includes a small .WSE sample script that demonstrates how to take the CMDLINE variable and parse it into the conventional sections as outlined above. If you are not looking for a full command line parsing routine, you can do simple checks with the built in WiseScript conditionals to check for existence of your own specific substrings.

Common Pitfalls:
  • WiseScript passes all command line switches it finds, including those that have special meaning to all WiseScript .EXEs. Avoid using common switches such as /s, /x, and /t since these all have specific meanings to all WiseScript .EXEs.
  • The WiseScript conditional If Contains checks for any occurrence of a specified substring. For instance, the strings /c and /checkin would both be true if you were checking for the substring /c.
  • The CMDLINE variable does not group any command line options by quotes. If you look for a specific substring or want a certain portion of the CMDLINE variable that may be enclosed in quotes, you need to include your quotes in the search criteria. See the attached sample provides an example of how to accomplish this.

By using the methods described in this article, you can affectively pass information to your WiseScript .EXEs on the command line with a minimum of formatting loss. By avoiding common pitfals and using the sample script provided with this article, you can easily use the CMDLINE variable. For additional information about the CMDLINE variable, contact Technical Support via the Tech Support Center at http://support.wise.com.


Legacy ID



24919


Article URL http://www.symantec.com/docs/HOWTO4341


Terms of use for this information are found in Legal Notices