Is there a way to step through a .bat script? The thing is, I have a build script , which calls a lot of other scripts, and I would like to see what is the order in which they are called, so that I may know where exactly I have to go about and add my modifications.
This question is related to
windows
batch-file
debugging
cmd
dos
Did you try to reroute the result to a file? Like whatever.bat >log.txt
You have to make sure that in this case every other called script is also logging to the file like >>log.txt
Also if you put a date /T and time /T in the beginning and in the end of that batch file, you will get the times it was at that point and you can map your script running time and order.
I found 'running steps' (win32) software doing exactly what I was looking for: http://www.steppingsoftware.com/
You can load a bat file, place breakpoints / start stepping through it while seeing the output and environment variables.
The evaluation version only allows to step through 50 lines... Does anyone have a free alternative with similar functionality?
Or.... Call your main .bat file from another .bat file and output the result to a result file i.e.
runner.bat > mainresults.txt
Where runner.bat calls the main .bat file
You should see all the actions performed in the main .bat file now
A quite frequent issue is that a batch script is run by double-clicking its icon. Since the hosting Command Prompt (cmd.exe
) instance also terminates as soon as the batch script is finished, it is not possible to read potential output and error messages.
To read such messages, it is very important that you explicitly open a Command Prompt window, manoeuvre to the applicable working directory and run the batch script by typing its path/name.
Facing similar concern, I found the following tool with a trivial Google search :
JPSoft's "Take Command" includes a batch file IDE/debugger. Their short presentation video demonstrates it nicely.
I'm using the trial version since a few hours. Here is my first humble opinion:
It deverves a try.
The only way I can think of is spinkle the code with echo
s and pause
s.
Make sure there are no 'echo off' statements in the scripts and call 'echo on' after calling each script to reset any you have missed.
The reason is that if echo is left on, then the command interpreter will output each command (after parameter processing) before executing it. Makes it look really bad for using in production, but very useful for debugging purposes as you can see where output has gone wrong.
Also, make sure you are checking the ErrorLevels set by the called batch scripts and programs. Remember that there are 2 different methods used in .bat files for this. If you called a program, the Error level is in %ERRORLEVEL%, while from batch files the error level is returned in the ErrorLevel variable and doesn't need %'s around it.
or, open a cmd window, then call the batch from there, the output will be on the screen.
you can use cmd \k
at the end of your script to see the error. it won't close your command prompt after the execution is done
Or.... Call your main .bat file from another .bat file and output the result to a result file i.e.
runner.bat > mainresults.txt
Where runner.bat calls the main .bat file
You should see all the actions performed in the main .bat file now
rem out the @ECHO OFF and call your batch file redirectin ALL output to a log file..
c:> yourbatch.bat (optional parameters) > yourlogfile.txt 2>&1
found at http://www.robvanderwoude.com/battech_debugging.php
IT WORKS!! don't forget the 2>&1...
WIZ
Source: Stackoverflow.com