开发者

Read command-line parameters to .bat from file

I have a build.bat file which uses %1 internally... so you might call:

build 1.23

I wanted it to read the parameter from a separate file, so I tried putting "1.23" in version.txt and doing:

build < version.txt

But it doesn't work. Isn't this how pi开发者_JAVA技巧ping works? Is what I want possible and if so how?


The FOR command in DOS has a form which parses files and assigns the tokens it finds to variables, which can then be used as arguments to other batch files. Assuming version.txt contains the single line "1.23", this batch file will open it, assign 1.23 to the variable, then call your original batch file, passing the variable's value as a command-line argument.

@echo off
for /f %%i in (version.txt) do call build.bat %%i

If version.txt contains more than one line, build.bat is called once for each line. Type help for at a DOS prompt to see what other features you might be able to use.


I think it would make more sense if you handle the file processing within the batch file on the off chance that version.txt is not edited correctly.

You should modify your script to parse the file to get the version if the .bat file is executed as:

     build FILE version.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜