Validating parameters in batch files

Keep in mind, though, that these "features" may vary with the operating systems used. The batch file's limitation to handle parameters up to I know of several occasions where these seemingly useless "features" proved very handy.Windows NT 4 introduced a set of new features for command line parameters: NUL ECHO Invalid argument: %1 ECHO. ECHO Where: number may be 1, 2 or 3 only GOTO: EOF :1 :2 :3 REM Code to do something with the validated argument starts here • • REM End of batch file NUL IF ERRORLEVEL 1 ( ECHO Invalid argument: %1 ECHO. ECHO Where: number may be 1, 2 or 3 only GOTO: EOF ) :1 :2 :3 REM Code to do something with the validated argument starts here • • REM End of batch file For a limited number of allowed arguments, this is a time saving technique.Do note, however, that labels are case sensitive, so you may not want to use this technique for "string type" arguments.We may need to know to which directory a file is to be copied, for example. There are many ways to achieve this user interaction.The most basic form of user interaction, of course, is the Tom Lavedas' New and Improved Data Input Routine! Predictably: So - think before you say: "Know what? The syntax: Is not some newly found virtue of the double quotes, but a display of a neat feature of stripping quotes from the argument variable, if the first and last character is a double quote.

Sometimes we need some user interaction in our batch files.The following trick uses ANSI to perform some key translation: the Enter key is translated to the F6 key followed by the Enter key. OS/2 users may want to take a look at User In PM, a utility written in VX-Rexx, displaying a small PM window asking for user input.Thus only one line of input can be entered, and pressing the Enter key sends the input to the temporary file USERINP. It creates a temporary batch file to set an environment variable to the typed input.The HTML Validator Command Line Processor can be run from a DOS command prompt and will accept arguments passed to it from the command line.NOTE: Since processing more than one file at a time using command line arguments is inefficient (unless you use the -f command), it is recommended that you use the drag and drop capability or the Batch Wizard to process multiple files.

Leave a Reply