问题
What command will make a batch file receive input from a text( .txt) file?
回答1:
Here's a transcript showing a batch file that will do what you want:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Pax> type qq.cmd
@setlocal enableextensions enabledelayedexpansion
@echo off
for /f "delims=" %%a in (%1) do (
echo.LINE^> %%a
)
endlocal
C:\Pax> type qq.txt
hello
goodbye
C:\Pax> qq qq.txt
LINE> hello
LINE> goodbye
The for
statement reads the lines one at a time into the variable %%a
(delims=
is needed otherwise spaces are used for breaks and you'll only get the first word on each line rather than the whole line.
%1
is the argument passed into the batch file, qq.txt
in this case.
Everything else is just support stuff that I use to get the best cmd.exe
environment set up.
回答2:
You can pass the names as parameters and capture them.
Look here for details.
来源:https://stackoverflow.com/questions/4895725/batch-file-which-will-take-a-text-file-as-an-input