You are creating a Windows batch script to automate monthly patching. The script has to read every line in C:\scripts\servers.txt and, for each server name it finds, append the text
Patching <server-name> in progress
to an existing file called patch.log that resides in the current user's %TEMP% folder. The log must not be overwritten and some server names may contain spaces. Which batch command fragment meets all of these requirements?
for /f "delims=" %%i in (C:\scripts\servers.txt) do echo Patching %%i in progress>"%TEMP%\patch.log"
for %%i in (C:\scripts\servers.txt) do echo Patching %%i in progress>>"%TEMP%\patch.log"
for /f "delims=" %%i in (C:\scripts\servers.txt) do echo Patching %%i in progress>>"%TEMP%\patch.log"
for /r C:\scripts %%i in (servers.txt) do echo Patching %%i in progress>>"%TEMP%\patch.log"
The FOR /F variant reads a text file line-by-line, so it can iterate through every server name stored in servers.txt. The option string "delims=" forces the parser to keep the entire line (including any embedded spaces) in the %%i variable instead of breaking at the default space or tab delimiters. Inside a batch file, the loop variable must be written as %%i (double percent signs). The append redirection operator >> adds each echo output to the end of %TEMP%\patch.log, preserving any existing content; using a single > would truncate the file on the first iteration. The other fragments fail because they either overwrite the log, treat the file name itself as the only loop item instead of its contents, or walk the directory tree rather than reading the text file.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the 'FOR /F' command do in a Windows batch script?
Open an interactive chat with Bash
What is the difference between '>' and '>>' in batch scripting?