This is probably the most popular way of putting known words at the beginning of your data line. Maybe not the words you wanted, but at least you don't have to use DEBUG. The basic idea here is to pass your entire data line(s) as an argument to one of the normal DOS commands, then have the DOS command kick out a message which will always contain the same first word (so we can make a batch file with that name) and will have our original data line on the same line. Remember, what we want is an error message, so be sure your data doesn't have what the command wants! If there is even a remote chance that legitimate data might be present, you should poison your data lines by numbering them. Here's a summary:
Typical contents of TEMP.BAT:
Enter new date (mm-dd-yy): Volume in drive C is MS-DOS
If you use DATE, you must create an ENTER.BAT that references your data starting at %4. FC is often used ahead of DATE to number the input data because it will poison the data (insuring no date info), remove blank lines, add a blank line at the end (to terminate DATE), and make the results easier to search with FIND for the desired line(s).
Typical use of DATE with FC:
dir > temp.bat
fc /n temp.bat nul | date | find " 2: " > temp.bat
Typical contents of TEMP.BAT: Enter new date (mm-dd-yy): 2: Volume in drive C is MS-DOSThe use of DATE described above is the single most useful trick in batch programming.
Typical contents of TEMP.BAT:
Enter new time: Volume in drive C is MS-DOS
If you use TIME, you must create an ENTER.BAT that references you data starting at %3. FC cannot be used ahead of TIME because the 1:, 2:, etc. outputs are interpreted as legitimate times. FIND with the /N option may be used if necessary (yuk).
Typical use of TIME with FIND:
dir > temp.bat
type temp.bat | find /n /v "unlikely" > temp.bat
echo.>> temp.bat
type temp.bat | time | find "[2]" > temp.bat
Typical output of TEMP.BAT:
Enter new time: [2] Volume in drive C is MS-DOS
TIME is not used as often as DATE because
TIME is not compatible with FC.
MOVE one two three four . > TEMP.BAT
Contents of TEMP.BAT:
Cannot move one - No such file or directory
Cannot move two - No such file or directory
Cannot move three - No such file or directory
Cannot move four - No such file or directory
If you use MOVE, you must create a CANNOT.BAT that references your data
at %2.
Because of the requirement to use an exising
directory as the last argument, I can see no widespread use for the MOVE
error messages in batch programmimg.
MODE TEST.TXT > TEMP.BAT
Contents of TEMP.BAT:
Invalid parameter - TEST
MODE C:\TEMP\TEST.TXT > TEMP.BAT
Contents of TEMP.BAT:
Invalid parameter - C
If you use MODE, you must create an INVALID.BAT that references your data at %3. NOTE: unlike almost every other command, MODE under Windows 95 does not add a CR/LF at the end of it's output line! In other words, it generates what I refer to as a "line fragment" which can be concatenated with another line to create a new line:
echo test data> test.txt mode = > temp.bat copy temp.bat + test.txtResults in a TEMP.BAT containing:
Typical contents of TEMP.BAT:
Error - Can't open input file: Volume in drive C is MS-DOS
If you use EXPAND, you must create an ERROR.BAT that references your
data starting at %6.
The best part about using the error message
from EXPAND is that it ignores all blank lines in the input data file.
ATTRIB Accepts single command-line argument only. If more than one argument is supplied, an error message will go to the screen and a zero-byte file will result from any redirection. No input piping allowed. Argument must not be a file name. Typical use:
ATTRIB one > TEMP.BAT
Contents of TEMP.BAT
File not found - one
Here is an example of what happens if multiple arguments are supplied:
E:\>ATTRIB one two > TEMP.BAT
Parameter value not allowed - two
<< this is displayed on-screen
E:\>dir TEMP.BAT
Volume in drive E is HDC1_TEST
Volume Serial Number is 224B-B508
Directory of E:\
TEMP BAT
0 04-19-97 5:04p TEMP.BAT
1 file(s)
0 bytes
0 dir(s)
9,578,496 bytes free
If you use ATTRIB, you must create a FILE.BAT that references your data
at %4.
The ATTRIB error message might be used to
check that only one argument exists on a line of data, but the on-screen
error display may (or may not) be a problem.
FC one two > TEMP.BAT
Contents of TEMP.BAT:
File(s) not found : one
If you use FC, you must create a FILE(S).BAT that references your data
at %4.
FC in this context is nearly useless and is
included only for completeness.
Lost? Look at the site map.
Bad links? Questions? Send me mail.