Jul 26, 2007

MS-DOS Batch Script Tips

Never suppose to write windows bat file. But when recently try it, even it really ugly comparing with unix shell scripts, still something interesting to learn and enjoy:)

rem setlocal not to impact environment variables
setlocal

rem get current disk driver and directory in case needed resources in specific location
set workDriver=%~d0
set workPath=%~p0
%workDriver%
cd %workPath%

rem call some command/executed program here
rem then check ERRORLEVEL for error handling
if ERRORLEVEL 1 (set errorCode=1
rem change color for warning and fun :)
color 4e
echo Error encounter!
pause
color 0f
goto error)

Useful link:
Batch File Command Reference for Windows 2000
MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference

1 comment:

Waris Ali said...

Thanks for sharing the info, keep up the good work going.I really enjoyed exploring your site. good resource.
The information you share is very useful. It is closely related to my work and has helped me grow. Thank you!
Pycharm Download