从另一个传递参数调用批处理文件
我有以下批处理文件,运行时要求用户输入。这很好用。
@REM Sample batch file
SET PARAM1=""
SET PARAM2=""
SET /P PARAM1=Enter param1: %=%
SET /P PARAM2=Enter param2: %=%
@REM Process the params
我现在希望能够从另一个批处理文件调用此批处理文件并将参数值传递到上面的批处理文件,并且不会要求用户输入。我怎样才能实现这个目标?
I have the following batch file that when run asks the user for input. This works fine.
@REM Sample batch file
SET PARAM1=""
SET PARAM2=""
SET /P PARAM1=Enter param1: %=%
SET /P PARAM2=Enter param2: %=%
@REM Process the params
I want to be able now to call this batch file from another and pass the parameters values to the above batch file, and the user won't be asked for input. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信你想要这样的东西?
Test.bat 不带参数运行:
Test.bat 带参数运行:
替代方案,使用环境变量而不是命令行参数(另请参阅 ppumkin 的回答):
只需设置环境变量
globalparam1
并globalparam2
在您的环境或您调用的批处理文件中抑制提示:Test.bat run withoutsettingenvironmentvariables:
Test.batrunwithsettingenvironmentvariables:
注意:设置环境变量也可以在例如调用批处理脚本。
I believe you want something like this?
Test.bat run without arguments:
Test.bat run with arguments:
Alternative, using environment variables instead of command line arguments (see also ppumkin's answer):
Just set the environment variables
globalparam1
andglobalparam2
in your environment or your calling batch file to suppress the prompting:Test.bat run without setting environment variables:
Test.bat run with setting environment variables:
Note: setting the environment variables can also be done in e.g. a calling batch script.
在
main.cmd
中:在
caller.cmd
中:输出:
批处理脚本参数参考
In
main.cmd
:In
caller.cmd
:Output:
Reference for batch script parameters
caller.bat /.cmd
passTo.bat /.cmd
从 dos 或命令窗口或任何其他应用程序/快捷方式单独调用 passTo.bat
在另一个批处理中使用 caller.bat 中的设置变量
您可能必须使用 SETX
caller.bat /.cmd
passTo.bat /.cmd
Calling passTo.bat on its own from dos or command windows or any other application/shortcut
Using the set Variables from caller.bat inside another batch
You might have to use SETX