Batch file which will take a text file as an input [closed]

南楼画角 提交于 2020-01-07 06:42:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!