Friday, May 12, 2017

Windows batch file tips

Sometimes its difficult to debug the batch files to trace the errors.
One simple way is to just add:
@echo on
This will print all the statements executed in the batch file and you can know the error line.

~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S

Following command will disable displaying your commands / statements from the batch files.
So the execution looks clean.
@echo off
 ~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S
format-date-and-time-in-a-windows-batch-script
Provides a way to format the time stamp in nice way in batch command.
set "ts=%dt:~0,4%%dt:~4,2%%dt:~6,2%_%dt:~8,2%%dt:~10,2%%dt:~12,2%"
You may use it in script to log data.
 ~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S