[英]How to pass parameters from a batch file to another as strings
So the title may not be very explicit about what I'm looking for, but basically I have this code: 因此标题可能不太清楚我想要的内容,但是基本上我有以下代码:
echo python %2 "%1" >> activate_wrapper.bat
This code is inside a .bat file and it's purpose is to build another .bat file that will run a python script. 这段代码位于.bat文件中,目的是构建另一个将运行python脚本的.bat文件。 Thing is I don't want to write the value of %1 to activate_wrapper.bat, I want to write the string "%1".
问题是我不想将%1的值写入Activate_wrapper.bat,我想写入字符串“%1”。
Expected line in activate_wrapper.bat: Activate_wrapper.bat中的预期行:
python secondArg %1
What am I getting: 我得到什么:
python secondArg "firstArg"
Thanks in advance guys. 在此先感谢大家。
SOLUTION: 解:
echo python %2 %%1 >> activate_wrapper.bat
The computer cannot read your mind, it doesn't know you only want to expand one of the parameters! 电脑无法读懂您的想法,也不知道您只想扩展其中一个参数!
You must escape the %
to prevent expansion: 您必须转义
%
以防止扩展:
echo hello %2 "%%1" >> temp.txt
set something=whatever
echo hello %%something%% >> temp.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.