views:

406

answers:

5

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

A: 

Like VS ? Not that I know of.

As far as variable values go, you can always print them out.

ldigas
A: 

I use Notepad++ to at least give me colour coding when I'm writing/modifying.

Keng
+1  A: 

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

Don Dickinson
Also removing echo off is usually a great help in determining where exactly an error occurs.
Joey
Dr. Zim
+2  A: 

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.

nray
Nice. I did not know you could use parentheses around the do in the for. Now the "echo this" statements make sense for the for loop.
Dr. Zim
+1  A: 

Well i found one it name is Running Steps. You can read more about it at its Homepage . Anyway it supports breakpoints, step in step over and stuff like that :)

psicho
Now that is amazing!
Dr. Zim