can someone give a reccomendation on learning a batch files command?
October 9th, 2009
Posted by: admin
maybe y’all can give me a few of a simple batch file command?
By: a1ronnie22
By: a1ronnie22
Tags: batch file, Batch Files, Reccomendation

October 13th, 2009 at 11:39
Start with the DOS help command. It’s got a lot of info about the various commands that can be used via a batch file.
For example the FOR command is used to take input and fetch through it row by row and do something with each row.
For example here is a single line batch file which logs into each of my SQL Servers (as defined in the file machines.txt in the same folder) and runs a T/SQL command against each one (as defined in command.sql in the same folder).
@for /F %%a in (machines.txt) do sqlcmd -S %%a -i command.sql -E
Everything before the word do is the for command. Everything after the word do is the SQL command which is being run once for each machine name in the machines.txt file.
Batch file scripting is a lost art which is extremly powerful.
I’m sure that there are more sexy ways to have done this but probably not in a single line of code.