从文件读取命令行参数到.bat
我有一个 build.bat 文件,它在内部使用 %1...所以你可能会调用:
构建1.23
我希望它从单独的文件中读取参数,所以我尝试将“1.23”放入 version.txt 中并执行以下操作:
构建<版本.txt
但它不起作用。这不就是管道的工作原理吗?我想要的是否可能,如果可以,如何实现?
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 piping works? Is what I want possible and if so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DOS 中的
FOR
命令具有解析文件并将其找到的标记分配给变量的形式,然后这些变量可以用作其他批处理文件的参数。假设version.txt
包含单行“1.23”,此批处理文件将打开它,将 1.23 分配给变量,然后调用原始批处理文件,将变量的值作为命令行参数传递。如果
version.txt
包含多行,则为每一行调用一次build.bat
。在 DOS 提示符处输入help for
查看您还可以使用哪些其他功能。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. Assumingversion.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.If
version.txt
contains more than one line,build.bat
is called once for each line. Typehelp for
at a DOS prompt to see what other features you might be able to use.我认为如果在 version.txt 未正确编辑的情况下在批处理文件中处理文件处理会更有意义。
如果 .bat 文件执行如下,您应该修改脚本来解析文件以获取版本:
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: