Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch file debugger?

Is there a program like Visual Studio that allows you to debug (dos) batch files? What techniques could I use to debug? Martin Brown answered a batch file question with a nice for / each loop. I would love to see the values of the variables as they loop.

for /R A %i IN (*.jpg) DO xcopy %i B /M

like image 727
Zachary Scott Avatar asked May 13 '09 17:05

Zachary Scott


People also ask

Can you use debugger on batch file?

The debugger allows you to "single-step" through a batch file line by line, with the file displayed in a popup window as it executes. You can execute or skip the current line, continue execution with the debugger turned off, view the fully-expanded version of the command line, or exit the batch file.

How do I test a batch file?

Save your file with the file extension BAT, for example, test. bat. To run your batch file, double-click the BAT file you just created. To edit your batch file, right-click the BAT file and select Edit.

How do you debug a batch job?

A display appears when the job is ready to start, indicating that you may begin debugging the job. Press F10 to show the Command Entry display. Use the Command Entry display to enter any debug commands, such as the Add Breakpoint (ADDBKP) or Add Trace (ADDTRC) commands.


3 Answers

To print the values of the variables as they loop you could try:

for /l %A in (1,1,10) do (
    @echo %A
)

If you want to stop and examine each line as it is executed try:

for /l %A in (1,1,10) do (
    @echo %A
    pause
)

which will halt the script at each iteration.

Your example looks like a backup script for images;

for /R %i in (*.jpg) do (
    @echo %i
    xcopy %i %DESTINATION% /M
)

If you make a script of this you can pipe all the output to a log file, just don't forget to use %%i instead of %i if you're not typing this at the shell.

like image 152
nray Avatar answered Oct 27 '22 23:10

nray


you mean besides just doing an echo HERE I AM type of thing? i don't know of any. i just debug my batch files by remming out the actions and adding echo's until i know its working correctly. i also wrote my own one line "outputdebugstring" application that sends anything on its command line to the debugger, but that probably isn't necessary for most batches where you can just watch the screen. inserting "pause"'s can help slow things down too.

best regards don

like image 36
Don Dickinson Avatar answered Oct 27 '22 21:10

Don Dickinson


Running Steps is like the IDE. You get an 'Analyzer' which is the equivalent of a compiler. It shows you errors and warnings in your code. It has an integrated environment that allows you to step over, into, etc. It even unrolls for loops which I find awesome. Check it out at http://www.steppingsoftware.com. It's helped me a lot.

like image 39
Gonzalo Isaza Avatar answered Oct 27 '22 21:10

Gonzalo Isaza