如何连接批处理文件的命令行参数? [英] How to concatenate command line args for a batch file?
本文介绍了如何连接批处理文件的命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试将我的命令行参数与此连接:
I'm currently attempting to concatenate my command line arguments with this:
for %%a in (%*) do set "subject=%subject% %%a"
例如,如果我跑步
my.bat subject line here
它应该将我的主题变量设置为此处的主题行",保留空格.但是,目前在运行之后,我的主题变量设置为最后一个单词.我得到了这里"的主题值.
it should set my subject variable to "subject line here", preserving the spaces. However, currently after the run, my subject variable is set to the last word. I get a subject value of " here."
如何正确连接命令行参数?
How to concatenate the command line arguments right?
推荐答案
你就不能这样做:
SET subject=%*
或者启用延迟扩展,以便在解析过程中不会替换环境变量.
Alternatively enable delayed expansion so that the environment variables don't get substituted during parsing.
Setlocal EnableDelayedExpansion
for %%a in (%*) do set subject=!subject! %%a
echo %subject%
参见 %variable% 和 !variable! 的区别!在批处理文件中了解更多信息.
这篇关于如何连接批处理文件的命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文