Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug a .BAT script?

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.

like image 862
Vhaerun Avatar asked Oct 03 '08 06:10

Vhaerun


People also ask

How do I debug a batch script?

By adding pause command: One way to debug batch file is by executing the pause command or operation and halting the executing program if any kind of error is found or occurred then a developer can easily fix the issue by restarting the process.

Can you edit a batch file while it running?

You will be fine as long as you modify the batch file after the current executing line position byte offset at the end of the most recently parsed line of code. If you modify it before then it will start doing strange things (repeating commands etc..).


1 Answers

I don't know of anyway to step through the execution of a .bat file but you can use echo and pause to help with debugging.

ECHO
Will echo a message in the batch file. Such as ECHO Hello World will print Hello World on the screen when executed. However, without @ECHO OFF at the beginning of the batch file you'll also get "ECHO Hello World" and "Hello World." Finally, if you'd just like to create a blank line, type ECHO. adding the period at the end creates an empty line.

PAUSE
Prompt the user to press any key to continue.

Source: Batch File Help

@workmad3: answer has more good tips for working with the echo command.

Another helpful resource... DDB: DOS Batch File Tips

like image 107
Eric Schoonover Avatar answered Sep 18 '22 15:09

Eric Schoonover