There is no direct way to do it. But it's not impossible to create one.
Since Windows XP/Vista/7 came out the good'ole set of DOS batch commands has been greatly upgraded, although not many uses them or even RTFM (FOR /?
?)
So here I give you, a simple pure-batch TRACER that utilizes the FOR /F
line-parsing switch:
@ECHO OFF
FOR /F "delims=" %%L IN (%1) DO (
CLS
ECHO __________________________________________________
ECHO ENV. VARIABLES *BEFORE*
SET
ECHO __________________________________________________
ECHO LINE
ECHO %%L
ECHO __________________________________________________
ECHO Hit any key to execute the line ...
PAUSE > NUL
ECHO __________________________________________________
ECHO EXECUTE
%%L
ECHO __________________________________________________
ECHO Hit any key to fetch the next line...
PAUSE > NUL
)
ECHO END OF FILE
You can take it as a start and modify it as you go.
Here's how you'd use it:
DEBUG.BAT TEST.BAT
And I'll also give you a test file to try it out:
@ECHO OFF
ECHO Hello World!
SET aaa=1
SET bbb=2
ECHO Doing step 2
SET aaa=
SET ccc=3
ECHO Doing step 3
SET bbb=
SET ccc=
ECHO Finished!
This DEBUG.BAT
thing, however, due of its simplicity, has some limitations BUT which can be worked around if you slap enough BATCH-fu in there.
- It cannot process multi-line blocks :: This can be worked around by having the
FOR
commands parse tokens and build the lines as they come in, and IF
it encountered an open parenthesis, just dump the parenthesis block content to a temporary file and then call itself on the tempfile e.g. DEBUG tempfile.bat
- It cannot process jumps :: You can of course, do an
IF
check for a GOTO label
then do a FOR /F
to parse out label itself, then maybe utilize the second argument %2
of DEBUG.BAT
to specify the label to jump to, in which case if this very argument is specified you'd just spin the FOR /F
until the desired label came into view and then proceeds with normal debugging on the next line.
- There is too much information from a single
SET
:: Just do what you did with the SET > before.txt
and after thing but do it on each line and then run a cmd-line DIFF tools on the files (plenty are available on the net). Then you'll get a DIFF of each variable that has changed since last step. You might even be able to avoid the env. variables mess altogether by slapping in SETLOCAL
and ENDLOCAL
in there and then you'd get just the local SETs ... but YMMV.
Those are some. If you've found some show-stopping limitation or whatever enhancements would help you nail that last bug, feel free to just let me know (via the comments) and I'll try to help you if I can.
Hope this helps.