简体   繁体   English

如何将参数作为字符串从批处理文件传递到另一个文件

[英]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.

相关问题 如何通过引用另一个批处理文件将环境变量作为参数传递? - How to pass environment variables as parameters by reference to another batch file? 通过Powershell在批处理文件中传递参数 - Pass parameters in batch file from powershell 从另一个批处理文件调用一个批处理,并从外部批处理设置内部批处理文件参数 - Call a batch from another batch file, and set the inner batch files parameters from the outer batch 如何使用批处理文件将可变内容从csv文件传递到另一个文件 - How to pass variable content from csv file to another file using batch file 将具有特殊字符的参数从批处理文件发送到另一个批处理文件 - Sending parameters having special characters to another batch file from a batch file 如何使用另一个批处理文件中的变量启动Windows批处理文件 - How to start a windows batch file with variables from another batch file 如何在另一个过程中从另一个批处理文件运行一个批处理文件? - How to run a batch file from another batch file but in a separate process? 多次将参数传递给Windows批处理文件 - pass parameters to windows batch file multiple times 如何从第 N 个位置获取批处理文件参数? - how to get batch file parameters from Nth position on? 批处理-如何关闭从另一个批处理文件启动的批处理文件 - batch - how can I close a batch file that was started from another batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM