Advanced Batch File Tool Guide
Advanced Batch File Tool Guide
Everything you always wanted to put in an environment variable but were afraid to ask DOS, Windows, or OS/2 for . . . XSET: The easy way to write efficient batch files. XSET allows you to put EVERYTHING you want in a variable of the current environment and use it as if you had assigned it the value with the standard DOS command 'SET'. You will be able to write very efficient batch files including string manipulation, calculation, ... XSET is the most powerful environment variable manipulation program you have ever seen. It also has a very easy and intuitive user interface (very close to the 'SET' command). It is not a resident program; so it will not interfere with any of your other applications. XSET is fully compatible with MS-DOS (from 3.30), DR-DOS, NDOS, 4DOS, FreeDos, OS/2, and all Windows versions. XSET has seven major features: ----------------------------- XSET permits you to catch the output of any command (internal or external) or program and put it into an environment variable. - XSET has built-in commands to modify the output of a program or a string given on the command-line (extract a part of a string, ...) - XSET has a built-in full floating-point calculation functionality: You can program incremental loops, input a calculation string and output the resulting number, ... - XSET can manage variable contents of more than 128 characters (your path can now be as long as you want). - XSET has other built-in commands to give you access to some system data (date, time, ...) - XSET has built-in commands to clear the whole environment or restore a previously saved one. - XSET gives you access to high-level input/output user interface (line-editing, colors, windows, boxes, ...). More than sixty commands to do all that you need.
The Shareware concept .................................... Page 2 How to use XSET .......................................... Page 3 Examples of use .......................................... Page 4 Input explanation ........................................ Page 8 Syntax explanation ....................................... Page 8 Options and commands description ......................... Input commands ......................................... Date & time commands ................................... Disk & file commands ................................... Other commands ......................................... Input related flags .................................... Prompt related flags ................................... String related flags ................................... Regular Expressions .................................... Other flags ............................................ Special flags .......................................... Page Page Page Page Page Page Page Page Page Page Page 9 9 10 11 15 16 17 18 20 21 22
Data file ................................................ Page 23 XSET & XSET_MSG variables ................................ Page 25 Errorlevel / return codes ................................ Page 25 Installation ............................................. Page 26 Windows & OS/2 specifics ................................. Page 26 Problems ................................................. Page 27 Batch file programming: Hints & tips ..................... Page 29 Windows features ................... ..................... Page 30 How to contact the author ................................ Page 31 Year 2000 compliance ..................................... Page 32 How to register .......................................... Page 33
This package is Shareware. That means that you may try it for evaluation and, if you like it, you should consider paying the registration fee (see the last pages of the documentation. You will then be a registered user and so have access to free support and free correction of acknowledged bugs. The essence of "user-supported" software is to provide personal computer users with quality software without the high prices, and yet to provide incentive for programmers to continue to develop new products. If you find this program useful and find that you are using XSET and continue to use it after a reasonable trial period, you should register it. Shareware also mean that you may distribute this package everywhere and to anyone you want, providing that you always distribute the complete package. If you have access to any BBS, FTP server, E-mail server or any other kind of software distribution, feel free to share it with other people; this may be useful for them and the more people that use (and register) a shareware program, the more stable it will become and the more functionalities and enhancements will be added. Warning: If you paid to get this package (e.g., it was onto a floppy ------- with other programs, you downloaded it from a BBS), you only paid for the physical support (the floppy, the transmission fee, ...); this does not replace the registration fee. Note to software distributors: ----------------------------Nobody is allowed to make any benefit by distributing the XSET package. Only regular distribution fees are allowed (price of the floppy, of the network connection, ...). Standard disclaimer and agreement: --------------------------------XSET is supplied as is. The author disclaims all warranties, expressed or implied, including, without limitation, the warranties of merchantability and of fitness for any purpose. The author assumes no liability for damages, direct or consequential, which may result from the use of XSET.
Page 3 How to use XSET: --------------XSET will always assign what you tell it into a DOS environment variable. See also the section dedicated to Windows & OS/2 if you are using one of these environment. The main goals of XSET are: - to ask a question to the user (through the keyboard), - to catch the output of a program or a command, - to get pieces of information like current date and time, timestamp or size of a file, ... - to modify a string (contained in another variable, in a parameter, ...) like changing it to lower-/upper-case, performing a search on it, calculating the result of a mathematical expression, substituting a sub-string by another or extracting a part of it, - to handle variables longer than 128 characters. There are four ways to use XSET. 1. Like the normal DOS 'SET' command: XSET myvar="This is a test string" 2. To get an input from the user: XSET answer 3. To catch the output of a program or a command: dir c:\programs\myprog.c XSET myvar 4. To get various system or environment information: XSET myvar DATE Furthermore, to attain a high level of functionality you may add, to each of the above syntaxs, several option flags to modify the default behavior of XSET (for example /UPPER to translate into upper-cases, ...). Syntax: -----1. XSET [/OPTIONS...] <dosvar> read a string from standard input 2. XSET [/OPTIONS...] <dosvar>="string" equivalent to the DOS command 'SET' 3. XSET [/OPTIONS...] <dosvar> COMMAND [arguments ...] Type XSET /? to get online the full description of all functionalities (parameters and effects).
Page 4 Remarks: ------- Intensive use of DOS environment variables may require that you expand the size of your DOS environment space through the SHELL command. See the PROBLEMS section for more details. - As any program, XSET.EXE (and XSET32.CMD under Windows & OS/2) must be present in the current directory, or a directory in your PATH. Examples of use: --------------These examples are only intended to show you how powerful and intuitive the usage of XSET could be. The syntax of all the functionalities is described just after. Remark: In all the examples, the command XSET and its built-in commands are typed in upper-case and the environment variables names are in lower-case. This is only for readability; when you type it, you may mix lower-case and upper-case as you like. The case is only significant for argument strings you enter on the command-line. 1) XSET datevar DATE DD-MM-YY Assigns the current system date into the variable 'datevar' Type the DOS command 'SET' to see all the environment variables; you will get something like this: ... COMSPEC=... DATEVAR=dd-mm-yy (where dd,mm,yy are replaced by current day, month and year) ... (other variables) You can now use the variable 'datevar' in a batch file: ECHO the date is %datevar% 2) XSET /COLOR LIGHTRED /PROMPT "Enter your name: " name Inputs a string from the keyboard (as usual, the answer is terminated by <Enter>) and assigns it into the variable 'name'. The prompt appears in the specified color (or the equivalent attribute on monochrome displays). You can now use the variable 'name' in a batch file to select a personalized environment for each user: ECHO Hello %name%, have a good work session CD \%name%
Page 5 3) You can write a batch file with automatic loops rem -----------------set loop=1 :next ....... anything you want ....... rem Increments variable value XSET /MATH loop=%loop% + 1 rem Test if value equals 20 if not %loop% == 20 goto next rem -----------------4) You can write a batch file where the user may enter a calculation and use it as a number rem -----------------XSET /PROMPT "Enter your calculation: " /MATH calc echo result = %calc% rem ------------------
Page 6 5) More elaborate example of a login procedure rem ---------------------- LOGIN.BAT -------------------------------@echo off cls :BEGIN rem Ask login name from keyboard rem ---------------------------XSET /PROMPT "Enter login name : " login rem Test if directory corresponding to login name already exist rem ----------------------------------------------------------if exist c:\%login%\*.* goto OK rem Directory does not exist, ask to create it rem -----------------------------------------echo: echo Login '%login%' does not exist. rem Only "yYnN" keys are allowed rem ---------------------------XSET /PROMPT "Do you want to create it? (Y/N)" /UPPER ask KEY "YN" if %ask% == N goto BEGIN rem Create directory rem ---------------md c:\%login% :OK set ask= rem Go to user's directory and branch to personal rem batch file if any. rem --------------------------------------------cd \%login% if exist autouser.bat autouser.bat rem -----------------------------------------------------------------
6)
Page 7 You are able to use a single password input for several network connections rem ----------------------------------------------------------------echo off cls rem Ask login name from keyboard rem ---------------------------XSET /PROMPT "Enter login name : " login rem Ask password from keyboard (it is hidden while typing) rem -----------------------------------------------------XSET /PROMPT "Enter password : " pass PASSWD rem Connection to several network nodes rem ----------------------------------net use node1 ... %login% %pass% net use node2 ... %login% %pass% net use node3 ... %login% %pass% rem Overwrite variable containing password (to be sure) rem -------------------------------------set pass=something_longer_than_password_to_be_sure rem Clear variable containing password (to free environment) rem ---------------------------------set passwd= rem -----------------------------------------------------------------
7)
And much more ... See also README.BAT, ENVEDIT.BAT, EASY.BAT and DEMO.BAT
Page 8 Input editing: ============= When you input a string from the keyboard, you may use several edition facilities: When a default string is proposed: - if any editing character (Home, <-, ->, ...) is hit you may edit the proposed string, - otherwise, default string is erased and replaced by the new input you type in; this feature is only active for the first key you hit. Valid keys: Home End Left/Right Insert Delete BackSpace Ctrl-home Ctrl-end Escape Enter Begin of line End of line One character left/right Toggle insert on/off Delete current character Delete previous character Erase to begin-of-line Erase to end-of-line Erase whole input Accept input
If a timeout is specified (see /TIMEOUT flag) the function may automatically return if no key is hit before the specified time. Syntax explanation: ================== [...] are optional arguments; if they are not specified, a default is assumed. {...} are mandatory arguments; if they are missing from the command-line, they are read from the standard input device (usually the keyboard or, if using redirection, a file or the output of another command). String arguments have to be included in double quotes (") if they contain any special characters like characters interpreted by COMMAND.COM. See remark in section 'Problems'. This implies that all double quotes will be removed from the strings arguments. String arguments to option flags also have to be quoted ("") if they contain spaces, tabs or slashes (/). To actually include double quotes, use 3 double quotes ("""). Important remark about standard input: If XSET finds a file called _XSET_IN.TXT in the directory where the environment variable TEMP points to, it will use this file as input instead of standard input. This allow you to split a long line and is useful for Windows & OS/2 users.
Page 9 Options and commands description: ================================ Remarks: - In the following descriptions, the word 'function' stands for both 'option flag' and 'command'; in other words, any functionality of XSET. - The word 'result' in the option flags description stands for the current contents of the variable at the moment the considered flag is processed (i.e., after the already executed functions). Input commands: -------------KEY [string] This waits for a key to be pressed and assigns the result to a DOS environment variable. If a string argument is added to the command, only the characters appearing in the string are allowed; if another key is hit, you will hear a beep. Printable characters (ASCII code from 32 to 255) return the character corresponding to the key (ex: A returns 'A'). Non-printable characters (ASCII code lower than 32) return their decimal ASCII code preceded by a '#' (ex: Ctrl-A returns '#1'). Extended keys (arrows, function keys, Home/end, PageUp/PageDown, ...) return their decimal scan code added to 256 preceded by a '#' (ex: F1 returns '#315'). See your technical documentation for a list of your keyboard scan codes. If you used the /TIMEOUT flag, the program will return after the specified time if no valid key was hit. The resulting variable will be empty. string \e \r \b specifier special characters: esc \t tab enter \.. character .. (decimal) backspace \\ backslash
ex: XSET k KEY all keys are allowed ex: XSET/UPPER k KEY abc only keys 'aAbBcC' are allowed ex: XSET k KEY 123aAbB\e\r\328 only keys '123aAbB, esc, enter, up' PASSWD This reads characters from keyboard without echo on screen. It is intended to input a password or secret information.
Page 10 Date & time commands: -------------------Default output format for dates is set with the /DATEFORMAT option. DATE [format] This returns the system date & time. In parameter 'format', special characters will be replaced by system date and time: D day M month Y year h hour m minutes s seconds If you double the character, it will be preceeded by a '0' if only one digit. ex: ex: 3 April 1996 YYYYMMDD -> 19980403 D-MM-Y -> 3-04-98 hh:mm:ss -> 14:23:12
DAYOFWEEK This returns the system day in the week (0 = sunday, 1 = monday, ... ) DIFFDATE date1 date2 This returns the number of days between <date1> and <date2>. date1 format may be 'yyyymmdd', 'dd-mm-yyyy' or 'dd/mm/yyy'. You may even mix them. If <date2> is before <date1>, the result will be negative. Rem: if yyyy is lesser than 100, 1900 is added (1994 is the same as 94).
Page 11 Disk & file commands: -------------------For all the file commands, you may specify to use normal DOS filenames, or Windows long or short filenames. To use normal DOS filenames, use no flag. To convert to long filenames, use the /LFN flag (Windows 95/98/ME only). To convert to short filenames, use the /-LFN flag (all Windows). When using normal DOS filenames, they may be valid or invalid filenames. They will never be checked for existence. When using long or short filenames, the existence of the file is checked (you may give either long or short filename as input) and if the file does not exist the program returns an empty string. Filenames may be an absolute pathname or a relative one. They are resolved (canonized) following the normal DOS conventions. For DOS and short filenames, they are translated into uppercase, for long filemanes, they keep their 'real' case from Windows. The drive given as arguments to these commands must be a letter from 'a' to 'z' (or 'A' to Z') optionally followed by a period ':'. FPATH {file} This returns the full pathname of a filename. ex: XSET myvar FPATH ..\myprog.exe will put in myvar something like 'C:\PROGRAMS\MYPROG.EXE' ex: XSET /LFN myvar FPATH ..\myprog.exe will put in myvar 'C:\Program Files\My Program.exe' ex: XSET /-LFN myvar FPATH ..\myprog.exe will put in myvar 'C:\PROGRA~1\MYPROG~2.EXE'
Page 12 FDRIVE {file} This returns the drive of a filename. ex: XSET myvar FDRIVE myprog.exe will put in myvar 'C:' FDIR {file} This returns the drive & directory of a filename. ex: XSET myvar FDIR c:myprog.exe will put in myvar 'C:\PROGRAMS\EXE\' FEXT {file} This returns the extension of a file name (no period included). ex: XSET myvar FEXT c:\exe\myprog.exe will put in myvar 'EXE' FNAME {file} This returns the name of a file without extension. ex: XSET myvar FNAME c:\exe\myprog.exe will put in myvar 'MYPROG' FXNAME {file} This returns the name & extension of a file. ex: XSET myvar FXNAME h:myprog.exe will put in myvar 'MYPROG.EXE'
Page 13 TRUENAME {file} This returns the full truename of a file, solving all SUBST, ASSIGN and JOIN commands and some network names (for those networks compatible with MS_LAN redirector). This does not work under Windows NT, 2000, XP, ... ex: XSET myvar TRUENAME myprog.exe will put in myvar something like 'C:\PROGRAMS\EXE\MYPROG.EXE' XSET myvar TRUENAME h:myprog.dat (where h: is SUBSTed to C:\DATA) will put in myvar something like 'C:\DATA\MYPROG.DAT' XSET myvar TRUENAME h:myprog.dat (where h: is a network drive) will put in myvar something like '\\SERVER1\SMITH%SMITH\MYPROG.DAT' FSIZE {file} This returns the size of a file (in bytes). If the file is not found, the variable XSET_MSG = FILE-NOT-FOUND. FDATE {file} This returns the modification date of a file (dd-mm-yy). If the file is not found, the variable XSET_MSG = FILE-NOT-FOUND. FTIME {file} This returns the modification time of a file (hh:mm:ss). If the file is not found, the variable XSET_MSG = FILE-NOT-FOUND. DIR [drive] This returns the current directory of the specified drive. If no drive is specified, the current one is assumed. VOLLABEL [drive] This returns the volume label of the specified drive. If no drive is specified, the current one is assumed. BYTEFREE [drive] This returns the number of bytes free on the specified drive. If no drive is specified, the current one is assumed. If more than 20 MB are available, the function may report a wrong value.
Page 14 DENSITY [drive] This returns the drive density (in KBytes - 360, 720, 1200, 1440, 2880) of the specified floppy drive. If no drive is specified, the current one is assumed. This command returns the density of the drive, not of the floppy that currently is in it (it isn't even necessary for a floppy to be in the drive). The program returns '0' if the drive has an unknown density or it is not a floppy drive. DRIVETEST [drive] This returns the status of the specified drive. If no drive is specified, the current one is assumed. The result is a concatenation of one or more string(s) from 'READABLE', 'WRITEABLE', 'NOFORMAT', 'NOTINSERTED', 'INVALID', 'REMOVABLE', 'REMOTE', 'SUBST', 'RAM', 'HARDDISK', 'TAPE', 'OPTICAL', 'FLOPPY', 'CDROM' separated by '-'. ex: XSET test DRIVETEST a: This assigns to the variable 'test' a string like: 'READABLE - WRITEABLE - REMOVABLE' (floppy or 'READABLE - REMOVABLE' (floppy or 'NOTINSERTED - REMOVABLE' (floppy or 'NOFORMAT - REMOVABLE' (floppy
So, to test if you have write-access to a drive: XSET/SEARCH "WRITEABLE" test DRIVETEST a: Variable 'test' will contain 'WRITEABLE' or will be empty. Remark: A ZIP drive can emulate either a hard disk or a floppy. Therefore, you sometimes get, for the drive type, "FLOPPY", "HARDDISK" or nothing depending on the last emulation.
Page 15 Other commands: -------------MIN / {str1...strn} MAX \ {num1...numn} This returns the minimum/maximum value of numbers or strings list. If not all arguments are numbers, a string comparison (i.e., a comparison of ASCII codes of their characters) will be performed. Rem: A string may not contain <space> or <tab>. ex: XSET var MIN 3.6 -4 9.02 %num% XSET var MAX 3.6 $5 abc 3.9j CPU This returns the processor type: 0 for 8088/8086/80186, 2 for 80286, 3 for 80386, 4 for 80486, 5 for Pentium There is no difference between DX and SX processors. Any non supported processor compatible with a Pentium should be reported as Pentium. Remark: some DOS emulators (like OS/2) emulate a 386 CPU and will report it even with a 486 or Pentium. RANDOM n1 n2 This function returns a random integer number between n1 and n2 (included). This may be useful to choose a random message from a collection, ... ERRORLEVEL This returns the errorlevel code of the last command issued. This function is only valid for - MS-DOS COMMAND.COM 3.30, 4.00, 4.01, 5.00, 6.00, 6.20, 7.00 (Win 95) - NDOS 6.0, 4DOS 4.02 - IBM PC-DOS 3.30, 6.10, 6.30 - OS/2 DOS box 1.30, 2.10, 2.11 and 3.0 - Windows NT 3.51, NT 4.0, 2000 If a version is not supported, this returns -1 but you may force XSET to know about your version: - run the program ERRLEVEL.EXE included in the package - if it displays one line (and no more than one) like: ERRORLEVEL=xxx (where xxxx is a 4-digits hexadecimal number), type the command 'ERRLEVEL > XSET.INI' - the XSET.INI file just created must always stay in the same directory as the program XSET.EXE to be used. VARCOPY variable This is strictly equivalent to 'set dosvar=%variable%' but allows the copying of variables longer than 128 characters. 'var' will contains '-4' (providing than %num% >= -4) 'var' will contains '$5'
Page 16 Input related flags: ------------------These are modifiers that can be used to customize the user's input. /DEFAULT set current value of variable as default value for input. - this option may be disabled with /-DEFAULT ex: set name=SMITH XSET/DEFAULT/PROMPT "Enter your name:" name /TIMEOUT n breaks the input if no key was hit after n seconds; once any key has been hit, you may edit your line during any time you need. If you didn't hit any key before n seconds, the input is cancelled and the resulting DOS environment variable is set to empty (i.e., deleted) or to its previous value if the /DEFAULT flag was used. - if the time-out delay has been reached, the program will set the DOS environment variable XSET_MSG to TIME-OUT (to let you check for it), - if n = 0, the program will check for type-ahead (i.e., XSET will enter into edit mode only if a key was hit at the moment of the check), - if n < 0, time-out will be active during the whole input process; if you wait more than abs(n) seconds between two keys, the program will return the string typed so far. - this option is only active if standard input is not redirected, - this option is also active with the KEY command (see further). - this option may be disabled with /-TIMEOUT /LINE n This reads the <n>th line from the standard input device (instead of the first one). -1 will read the last line, -2 will read the line before, ... ex: dir *.exe XSET /LINE -2 /WORD 3 filenb This will get the number of files matching *.exe and assign it to DOS environment variable 'filenb': - read the line before the last one from the output of the 'dir' command (something like ' 15 file(s) 87912 bytes'). - pick up the third word on this line. - if the file does not contain enough lines, the program will set the DOS environment variable XSET_MSG to END-OF-FILE (to let you check for it).
Page 17 Prompt related flags: -------------------These flags are interpreted immediately, before any function. In order to move the cursor, you need to actually output something with the /PROMPT flag - this may be an empty string (""). /CLS Clears the screen. /PROMPT string Display a message on the screen. /COLOR color Set color for prompt (and border if any). Valid colors: BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, DARKGRAY, LIGHTGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE Remark: If a monochrome video card is detected, the /COLOR and /BACKGROUND options will be ignored; if you have a color video card and a monochrome display screen, the colors will be mapped by the screen itself as with any other program. /BACKGROUND color Set background color for prompt (and window if any). Valid colors: BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY /BLINK To choose a blinking prompt (compatible with /COLOR). - this option may be disabled with /-BLINK. /XPOS x Set cursor to column x before displaying prompt. +x or -x sets the cursor to x columns after or before current /YPOS y Set cursor to line y before displaying prompt. +y or -y sets the cursor to y lines after or before current /WINDOW left top right bottom Draw a window (using color specified with /BACKGROUND). ex: XSET/BACKGROUND RED /WINDOW 3 2 12 8 Draw a red window from position (column 3, line 2) to position (column 12, line 8). /BOX Draw a window (using color specified with /BACKGROUND) around the prompt (specified with /PROMPT); your answer (if any) will be outside the box. ex: XSET/BACKGROUND RED /BOX /PROMPT "Hello" Draw a red window with the prompt inside. /BORDER Add a border inside a window (specified with /WINDOW or /BOX). - this option may be disabled with /-BORDER.
ex: XSET/BACKGROUND RED /BOX /BORDER /PROMPT "Hello" XSET/BACKGROUND RED /BORDER /WINDOW 3 2 12 8 /-BORDER /WINDOW 3 12 12 15
Page 18 String related flags: -------------------/UPPER and /LOWER This translates the result into upper/lower-cases. Characters like ... are also translated to EA... (or ea...). - This also affects the arguments given to the KEY command, - This also affects the first argument given to the /SEARCH, /INDEX and /CHANGE option flags. May be negated by /-UPPER or /-LOWER. /LEFT n, /RIGHT n This picks the leftmost / rightmost <n> characters of the result (or less if result is shorter than <n>). ex: XSET/LEFT 2 drive=%full_pathname% Remark: if n < 0 it will be interpreted as {string length - n} ex: XSET/LEFT -5 t="12345678" returns "123" XSET/RIGHT -5 t="12345678" returns "678" /MID m n This picks the <n> characters starting from the <m>th one of the result (or less if result is shorter than <m> + <n>). First character has index 1. ex: XSET/MID 2 5 var=%other% Assigns characters 2, 3, 4, 5 & 6 from %other% to 'var'. Remark: if m < 0 it will be interpreted as {string length - m} ex: XSET/MID -3 2 t="12345678" returns "67" /COUNT This returns the number of words (separated from other ones by any number of blanks or tabs) in the result. Other word separators may be specified with the /SEPARATOR flag. /WORD n This picks the <n>th word (separated from other ones by any number of blanks or tabs) of the result. Other separators may be specified with the /SEPARATOR flag. If no word is found, an empty string is returned. /SEPARATOR string This uses the characters from 'string' as word separator. This option is intended to be used with /WORD and /COUNT. ex: XSET/SEPARATOR "+-*/()" /WORD 3 var="25+6*(-72+3)" Assigns the string 72 to 'var' (25 is first word, 6 is second, ...). /LENGTH This returns the length of the result.
Page 19 /REVERSE This reverts the result string (the first character becomes the last one). /SEARCH string This returns the portion of the result matching <string>. ex: XSET/PROMPT "Enter your name: "/UPPER/SEARCH "SMITH" var If the answer contains 'SMITH' (even in lower-cases), variable 'var' will be assigned to 'SMITH'; otherwise, variable 'var' will be empty. /*SEARCH string The argument is a 'Regular Expression' (see further). /INDEX string This returns the index (position) of the portion of the result matching <string>. First character has index 1. /*INDEX string The argument is a 'Regular Expression' (see further). /CHANGE string1 string2 This changes (substitutes) all occurrences of <string1> to <string2> in the result. ex: XSET/CHANGE "oldstr" "newstring" var=%answer% /*CHANGE string1 string2 The first argument is a 'Regular Expression' (see further).
/MATH This performs a mathematical calculation on the string. Mathematical operators: - on integer and floating point values: - on integer values: Logical operators: = < > <= return 1 Rem: '*' '+' + - * / () ^ (exponent) % (modulo)
>= <> if true, 0 if false may be used to 'and' values, to 'or' them.
Precedence:
+ and - have the highest precedence, all other expressions are evaluated from left to right.
ex: XSET /MATH var = "3+(2*5) + %new% + (%loop% <= 5)" XSET /MATH /PROMPT "Enter your calculation" result
Page 20 Regular Expressions: ------------------UNIX-like regular expressions are a way to describe a string template to match; it may be used to specify the format of a string: - only digits, - only upper-case letters, - at least one letter and afterward digits and letters, ... They are very powerful tool to express the argument given to a string searching mechanism. They are used with the /*SEARCH, /*INDEX and /*CHANGE option flags. A regular expression is one or more occurrences of one or more characters. The following symbols have a special meaning: ^ $ . \ * + ? [] start of line (see also below: 'inside set of characters') end of line any character quote next character (i.e., do not treat it as a special character) match zero or more time preceding character (or character set) match one or more time preceding character (or character set) match one or zero time preceding character (or character set) set of characters inside set of characters: ^ means non-inclusion - means range ex: [aeiou0-9] [^ae0-9] ex: ^[a-z]* [a-zA-Z0-9]$ match a, e, i, o, u, and 0 through 9 match anything but a, e and 0 through 9 match the first string of a line containing only lower-case letters match the last string of a line containing only letters (upper-case and lower-case) or digits
ex: XSET /*SEARCH "[a-zA-Z]:[a-zA-Z0-9_\\.]+" myvar will search for a standard DOS filename (from standard input) [a-zA-Z] match any characters included in the range 'a' to 'z' and 'A' to 'Z'. : match the character ':' [a-zA-Z0-9_\\.] match any characters included in the range 'a' to 'z', 'A' to 'Z', '0' to '9' and the characters '_', '\' and '.'. \\ match the character following the first '\', in this case a second '\'. + match one or several characters (the preceding one, which here is a set of characters). This instruction matches any filename of the form 'drive:pathname' (ex: C:\DIR\OTHERDIR\FILE.EXT). XSET/*SEARCH "[0-9]+" var=%answer% Variable 'var' will be assigned to the first occurrence of a string
Page 21 Other flags: ----------/APPEND This adds the result to the existing variable instead of overwriting it. This allows you to bypass the 128 character limit of DOS (see /VIEW). May be negated by /-APPEND. ex: XSET/APPEND path=";c:\msc600\bin;c:\msc600\binb" /DATEFORMAT format This specifies the output format for dates. In parameter 'format', special characters will be replaced by system date and time: D day M month Y year h hour m minutes s seconds If you double the character, it will be preceeded by a '0' if only one digit. ex: ex: 3 April 1996 YYYYMMDD -> 19980403 D-MM-Y -> 3-04-98 hh:mm:ss -> 14:23:12 This modifies all DOS environments in memory; i.e., not only the current shell (COMMAND.COM) environment but also the previous ones (if any). ex: XSET /ALL /APPEND path=";c:\bin"
/ALL
Warning: If one of the environments is not big enough to contain the new variable, no error message is displayed. May be negated by /-ALL.
Page 22 Special flags: ------------Note: Except if you only use XSET as an enhanced display program (to allow you to use colors, windows, boxes, ...), you always need a DOS environment variable name except for the flags described below. XSET /ALL XSET /CLEAR XSET /VIEW modifies all environments in memory. deletes all variables from the current DOS environment. shows all variables from the current DOS environment. This is strictly equivalent to 'SET' but will show variables longer than 128 characters.
Rem: If you use XSET to assign values longer than 128 characters to a variable, they will appear truncated when displayed by the DOS command 'SET'. This is only a display problem of the command 'SET'; all the variables are correctly stored and can be used without problem by any program. XSET /VIEW var displays the value of variable 'var'. This is intended to be used to pass a variable's content to the standard input of another program. This is equivalent to 'ECHO %var% ..." except that it can handle variables longer than 128 characters and you can use option flags with it. LABEL a: feed the program 'LABEL' with the first 7 characters of environment 'myvar'. save all environment variables into the file SAVEFILE.VAR.
loads variables from standard input. Variables must have been saved with command 'XSET /VIEW'. load all environment variables from the file SAVEFILE.VAR.
Page 23 XSET Data file: ============== In order to speed up execution time and to break the 128 character limit of the command-line, you may put several XSET command-line in a data file and execute them as a whole (you only load XSET once). XSET /FILE filename section To use it, just create a file containing a section name between square brackets followed by the XSET command-line you want. These lines are the same as the ones you put in a batch file but without the XSET program name. ex: XSET /FILE mydata.xst test1 Data file MYDATA.XST: ... anything ... [Test1] # This is a comment line # To uppercase all following functions /UPPER # Get current date datevar DATE # Ask user's name /CLS /BACKGROUND RED /COLOR WHITE /BORDER /WINDOW 1 1 80 25 /XPOS 10 /YPOS 5 /BLINK /PROMPT "Enter your name: " namevar # Echo answer /CLS /PROMPT "Hello %namevar%, current date is %datevar%" [End]
Page 24 Remarks: 1. The % character will be used in the same way as in batch files to delimit variable names. To use an actual % character, you have to double it. 2. All the option flags you use in the same run (in either the command-line or inside a data file) are remembered in the following command-lines. 3. A data file cannot be called from another data file, although you may call several data files on the same line. 4. Section names are not case-sensitive 5. You must end your section with another section name between square brackets. A good practice would be to end each section with something like [END]. 6. A line may be commented by preceding it with a # character. 7. If not found in the current directory (or as an absolute filename), XSET will automatically add the 'BAT' or 'BTM' extension if no extension is specified and search in the PATH. This should allow you to specify %0 as filename. Warning: XSET may not find it if it is not in your path and you change the current drive/directory inside your batch file. 8. In order to let you put your XSET data inside the batch file itself, you may preced the data lines with two : characters; in this way they will be skipped by the batch file processing. ex: Batch file THISFILE.BAT ... XSET /FILE thisfile.bat test1 :: [Test1] :: # Ask user's name :: /CLS /BACKGROUND RED :: /COLOR WHITE :: /PROMPT "Enter your name: " namevar ::# Echo answer ::/PROMPT "Hello %namevar%" ::[End]
Page 25 XSET variable: ============= Because you sometimes want to use the same flags for a group of XSET commands (like /UPPER, /DEFAULT, ...), it would be nice to have a way to give default options to XSET. And there is such a functionality: the XSET environment variable. Before scanning the command line, the XSET program will look for the 'XSET' variable into the current DOS environment. If it exists, the XSET program will use the variable contents like option flags you would have given onto the command line. After that, it will use the option flags given onto the command line. Note that the command line options may overwrite those contained in the 'XSET' variable. ex: set XSET=/UPPER/DEFAULT/XPOS 5 /BLINK XSET /YPOS 12 /PROMPT "First name: " name1 XSET /PROMPT "Last name: " name2
This is also a way to reduce the length of your command line (remember that COMMAND.COM truncates all lines longer than 128 characters). Note that you may use XSET/APPEND to assign a very long line to the 'XSET' variable.
XSET_MSG variable: ================= This variable is intended to be assigned by the XSET program itself to a message to specify special events (like a time-out on input, ...). This variable is updated (or deleted from the environment) each time the program is called. See the related options and commands to get a description of the variable contents. Options and commands using the XSET_MSG variable: input from a file (see /LINE) /TIMEOUT Concurrent accesses could also set the variable (see 'Windows & OS/2' section. Errorlevel: ========== XSET returns several values you can check with the 'if errorlevel ...' command (see your DOS manual): 0: 1: 2: 3: 9: 10: normal termination syntax error environment space is full not enough memory to perform operation XSET forced a concurrent use of the temporary file (NT or OS/2) other error
Rem: with the ENVFREE command, XSET returns as errorlevel the number of bytes available in the environment. Because errorlevel is limited
Page 26 Installation: ============ - XSET.EXE is ready to use; no installation. Just copy XSET.EXE, this file, and XSET32.CMD in a directory of your hard drive (usually a directory included in your PATH). If you want to use the demos included in this package (DEMO*.BAT), they must be copied in the same directory as the XSET program. - To get a registered version of XSET, fill the last page of this document, and send it to indicated e-mail address; you will receive the password required to register your version with XSET/REGISTER.
Windows & OS/2 specifics: ======================== Windows 3.x, 95, 98, and ME are still MS-DOS based, thus are considered in this documentation as normal DOS and can directly use the XSET.EXE program as described above. Under Windows NT/2000/XP/2003 or OS/2, the situation is different. XSET runs perfectly in a DOS box ; as long as you want to execute XSET inside a DOS batch file, it is very simple: - OS/2 automatically launches a DOS box when executing a batch file (.BAT extension). - Windows launches, by default, .BAT files in a Windows command prompt box; you have either to associate COMMAND.COM to .BAT extension (to have it permanently) or to manually launch batch file with 'COMMAND/C filename.bat'. If you want to use XSET to modify Windows or OS/2 native environment variables, instead of using directly 'XSET.EXE', use 'CALL XSET32' with all the same arguments as XSET. Ex: XSET VAR TIME becomes CALL XSET32 VAR TIME
There is a limitation, you cannot use redirections with a batch file. If you want to pipe the output of a program to XSET, just write what you want to redirect to XSET in a file called %TEMP%\_XSET_IN.TXT (this file will be erased automatically). Ex: becomes program XSET /UPPER VAR program > %TEMP%\_XSET_IN.TXT CALL XSET32 /UPPER VAR (see warning below)
You only need to redirect the output of XSET for the /VIEW command. Therefor, you do not even have to call XSET32, just use XSET as normal (because this command does not modify environment variables, it just displays them). Warning: be sure the environment variable TEMP points to a directory where you have write access (and there is no backslash '\' at the end, otherwise you may edit the batch file).
If you want to use XSET from REXX, it will work but you need to modify XSET32.CMD to replace '/NT' by '/REXX'.
Page 27 Concurrent use ============== Concurrency is correctly handled under Windows 2000 or later. Under Windows or OS/2, calls to XSET are serialised, unless you set, in the calling batch file, the variable XSET_TMP to a different directory path. You can use the same technique for concurrent batch files that need to redirect the output of a command ( > %TEMP%\_XSET_IN.TXT). XSET will try to serialise calls to XSET 40 times and wait about half a second between each try. After 40 times, it will continue and set the XSET_MSG variable to 'CONCURRENCY-PROBLEM'. Problems: ======== 1. If the size of your environment space is not large enough, you will receive an error message 'XSET : not enough environment space.' This is not a bug, it is because the environment space reserved for the variables is too small. You must increase it by specifying an argument to COMMAND.COM. By default, MS-DOS reserves 256 bytes environment space; this is usually insufficient (especially under Windows 9x/ME). Try 640 bytes (or more) by adding '/e:640'. * MS-DOS: modify the line 'SHELL=...' ex: SHELL=COMMAND.COM /E:640 /P If this problem is encountered in a secondary shell (i.e., you run the batch file from a menu that runs a secondary shell) here is a way to work around the problem (this is a DOS problem that could be avoided by the program that runs the secondary shell): put in your AUTOEXEC.BAT a line such as: SET TO_DELETE=something_very_long_... and, before using variables in the SECONDARY shell delete this variable with the command: SET TO_DELETE= Other ways to work around this limitation: * patch COMMAND.COM; see file 'PATCHDOS.TXT' for more details. * Windows 95/98/ME: Use PIFEDIT to create or modify _DEFAULT.PIF in the directory containing COMMAND.COM to have it point to 'command.com /e:2048'. * Windows NT, 2000, XP, ...: This problem does not occur.
Page 28 - If you use special characters like <> you will have a problem because COMMAND.COM interprets these characters as redirection commands before giving the control to the program you call. This is a general DOS problem, but it is very easy to work around. ex: XSET /MATH var=(%loop% + 3) > 2 (suppose loop=1) Although you think you call XSET to check if 4 is greater than 2, COMMAND.COM interprets it as "put into a file named 2 the result of 'XSET /MATH var (1+3)'" You will have the same result with '<' and ' '. The best way to ensure that all special characters you use will be given 'as is' to the program you call (XSET or another one) is to enclose your strings between double quotes: XSET /MATH var="(%loop% + 3) > 2" Be careful not to quote XSET reserved words (commands or flags) and variable names. So do not write XSET var "MIN abc <def> gh" or XSET "var MIN abc <def> gh" but XSET var MIN "abc <def> gh"
- If you want to use the character '%' in a batch file, remember that this character is reserved for DOS environment variables; so, if you want to use a 'real' % character, you have to write '%%' in your batch file. ex: XSET /MATH var="%other_var% %% 7" This line in a batch file will put into variable 'var' the result of '(contents of variable other_var) modulo 7'. Notice that the use of double quotes doesn't affect the way that COMMAND.COM interprets the % character; you must double the % character even if it is quoted. - Blinking usually does not work in a Windows DOS box. Instead, a light background is displayed.
Page 29 Batch file programming: Hints & tips ==================================== 1. Whenever it is possible, use 'SET var=...' instead of 'XSET var=...' because SET is an internal COMMAND.COM's command and is quicker than calling an external program. ex: To clear a variable, use instead of SET myvar= XSET myvar=
If you are sure that the variable 'var1' is shorter than 100 characters, use SET var2=%var1% instead of XSET var2 VARCOPY var1 2. COMMAND.COM reads and executes batch files one line at a time; that means that it reads one line, execute it and rereads the file from the beginning to the next line. If you do not have a good disk-cache installed, it is not efficient. Furthermore, when using 'REM' in your batch files to insert a remark, COMMAND.COM reads the comment line, execute it (i.e., does nothing) and rereads the file from the beginning to the next line. To avoid this, there is a trick: use '::' instead of 'REM'. ':' is understood as a label to be used by the 'GOTO' statement (see your DOS documentation); this line will never be executed. As a label cannot begin with a ':', this line will not be considered as an executable line, nor as a label. ex: replace by REM This batch file is intended to ... :: This batch file is intended to ...
3. To echo an empty line on the screen, use 'ECHO:' 4. To test for the existence of a directory, test for the existence of the file 'nul.ext' in it (the filename 'nul' should be sufficient except on a Novell network, NTFS,... ). ex: if exist c:\mydir\nul.ext echo The directory 'MYDIR' exists. 5. If an environment variable contains a directory name ending with a '\', COMMAND.COM will not accept to chdir to this directory. ex: set dir=c:\mydir\ cd %mydir% ==> Error message: Invalid directory The trick (to avoid removing the trailing '\') is to add a '.' ex: cd %mydir%. (note the trailing '.') See also DEMO.BAT in this package for other tricks. 6. How to create *one* version of the script that could be used on DOS, all Windows systems ? In your scripts, always use 'CALL XSET32 ...' (normal NT syntax) On DOS and Windows 9x/ME machines, copy XSET.EXE to XSET32.EXE.
Page 30 Windows features: ================ Windows uses a special variable 'windir' which determines the directory for Windows *.ini files. As it is in lowercase, you normally cannot use it - even to check it. If you give it as parameter to XSET (in lowercase), it will preserve it and allow you to use it - for example to copy it to a normal variable. Interesting note: ---------------You may use it to have a different profile for each user. If you set 'windir' BEFORE starting windows, it will use that value. That way you don't need to have WIN.COM in each user's directory.
page 31 Additional information: ====================== Feel free to contact me with any problem or question. If you have an electronic mail connection, this is the quickest, cheapest and easiest way (this would allow me to test your batch files in case of problems or bug). Web: http://xset.tripod.com or http://www.bigfoot.com/~xset (internet)
Page 32 Year 2000 compliance ==================== XSET has been intensively tested by me and by several big companies using it daily and no problem is known at this time regarding the year 2000.
Page 33 How to register =============== 1. Check for latest version --------------------------First try to connect to XSET Web site (see previous page) to get the most up-to-date version. 2. Registration info -------------------Please complete the following form and send it to me (via E-mail if possible). You will then receive the password to register your version of XSET (Type 'XSET/REGISTER'). Try to answer the questions, as it will serve for my statistics to enhance the program in the best way (that means your way!). 3. How to pay ------------Without additional fee ---------------------* Cash Almost any currency is accepted, please ask for the exact amount. * Put the money onto my bank account Argenta Bank - Belgium - 1300 Wavre Swift number (BIC): ARSPBE22 - Bank code (IBAN): BE92 9799 4804 1023 account 979-9480410-23 * International Postal Money Order: You give the money at your local mail office, this is no cheque. In US it is called 'USPS Authorization to Issue an International Money Order'. * Paypal (http://www.paypal.com): - only from a paypal account or a bank account, no bank/credit card (but you can put money from your credit card on your Paypal account) - use e-mail xset@bigfoot.com * Credit cards: via Paypal account With 15 EUR additional fee --------------------------------* American Express International Money Order: Almost any currency is accepted, please ask for the exact amount. If you have any problems due to change or whatever, please contact me and I will explain to you how to pay in another currency. Do not be discouraged by money transfer problems, simple solutions exist to easily register from anywhere around the world (they generally are dedicated to each geographical and/or social situation, so I cannot describe them all in this document).
XSET 5.52 Registration Form Date ________________ Name: _____________________________________________________________ (Company:) _____________________________________________________________ Address: _____________________________________________________________ _____________________________________________________________ _____________________________________________________________ Tel: _____________________ Fax: _______________________
XSET features you find most useful: ____________________________________ ________________________________________________________________________ Features you would like to see added (use additional pages, if necessary): _________________________________________________________________________ _________________________________________________________________________ _________________________________________________________________________ MS-DOS (or DR-DOS,...) version : ___ Windows or OS/2 version: ___ shell (4DOS, NDOS,...) : ________
Number of machines to use XSET on: __________________ Personal or professional use ? ______________________ Price: Personal use : 15 EUR x _____ Business use : 30 EUR x _____ Network - Site : 250 EUR x _____ Total: _________