Finally I was introduced to the world of DOS Batch Programming. I learned the hard way that Batch processing is a lot more than I would have ever thought it to be. Can you image my surprise when I learned that you can do file manipulations using DOS??? And to add to that, even binary files can be manipulated using the simplest batch commands of DOS?!! Ever heard of the command FOR in DOS! Well! If you add the /F switch with the same, you get a wonderful file handling capabilities for DOS. Read up more on the posts by Mic, an avid and resourceful DOS Batch person, who I think would be able to answer all DOS Batch related questions you post to Batch World group on Yahoo!: Batch World
Well I have a fine time trying to work out what all I could to with DOS to help in my Automation work, currently I have managed to get a working script which will help me in installing images stored by me on a server and a user configuration in which user selects his choice of OS file system to install and execute his test framework on:
FOR /F %%y IN (c:\OSCount) DO CALL :READ %%y
SET /A countWr=%my_return% 1
> c:\OSCount echo %countWr%
SET /A v_sum=%1
SET /A count=1
FOR /F %%x IN (c:\MyFileA.txt) DO CALL :ABC %%x
ENDLOCAL & SET /A my_return=%v_sum%
IF %count%==%v_sum% ECHO This File %1
ENDLOCAL & SET /A count =1
The above script is reading a file (MyFileA.txt) and getting the line number to be read from another (OSCount) file, which is then incremented for the next execution (the file is written to, we can also append to the file by using double greater than symbol – >>). Also, the variables are being passed as parameters from one sub-routine to another and then returned. So, finally, when we reach the first sub-routine again, the OSCount file is contains an incremented new value and when we run it again, we can get the next line in the file MyFileA.txt.
Although with the above script you can find out many things you can do with DOS batch commands – read a particular line in a file, write or append a line to a file, and even sub-routines in DOS!!! I never knew these were there. The SETLOCAL – ENDLOCAl actually defines a sub-routine in DOS. For debugging DOS batch files, you just do an @ECHO ON at the beginning of the file and execute the script through the DOS command line and voila, you can actually pin-point where you are going wrong – which line or variable is returning what value and where and when.
So, folks all I can say is that get your Windows machines pumped up and start using the powerful features of DOS which you might have never know existed… (PS: I have not added the code sent by Mic here as the link should take you to that, which is more nicely structured and concise!! My code is just a bunch of statements more meant to give an idea of what all DOS is capable of doing…)