Difference between revisions of "Batch File Scripting Tips"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
(New page: Here are collected various batch file scripting tips for use when writing .bat files for use with WPKG. If a batch file gives a degree of output to the screen it can overwhelm WPKG and th...)
(No difference)

Revision as of 18:38, 3 December 2008

Here are collected various batch file scripting tips for use when writing .bat files for use with WPKG.

If a batch file gives a degree of output to the screen it can overwhelm WPKG and the batch script hang. Lessen the output of commands by appending each with ' 1>NUL 2>NUL'. This will prevent commands echoing their messgaes (from use of the echo command), results and errors to the screen and thus to WPKG. Also, begin a batch script with '@echo off' so that the commands themselves aren't displayed.

Where a % character references a variable from within a batch file, where a single % can be used from the command-line a double %% has to be used from within a batch file.

The Windows shell and some command-line programs don't like spaces appearing in file or directory names. For example when using such wildcards as %PROGRAMFILES% in %PROGRAMFILES%\some-directory\some-program.exe where we don't know whether or not %PROGRAMFILES% contains a space, use "%PROGRAMFILES%\some-directory\some-program.exe"