使一个批处理文件从另一个批处理文件获取参数 [英] Having a batch file get parameters from another batch file
问题描述
是否可以使一个批处理文件读取另一个文件并从另一个文件获取诸如密码之类的数据?例如 批处理文件1:
Is it possible to have one batch file that reads another and gets data such as a password from another? for example batch file 1:
@ echo off
//get data from batch file 2
set /p pass=Password:
if pass == password goto a
if not pass == password goto b
:a
//something that happens if password is good
pause
exit
:b
echo wrong password
pause
exit
批处理文件2:
MyPassword
MyPassword
推荐答案
以call
ed/start
ed的方式批量传递参数:
Parameters are passed in batch over the way they are call
ed/start
ed:
bat1.bat:
set /p input= Parameter to pass here:
start "Title here" bat2.bat %input%
bat2.bat
echo Passed value: %~1
参数通常具有从1到9的索引,并且批处理文件本身的路径保留"为0.
The parameters usually have the indexes from 1 to 9 and 0 is "reservered" for the path of the batch-file itself.
替代:
您可以使用以下命令读取en可执行文件的输出:
You can read the output of en executable using for:
bat1.bat
echo This will be displayed in bat2
bat2.bat
for /f "tokens=*" %%i in ('bat1.bat') do echo %%i
第二个批处理文件在哪里读取第一个批处理文件的输出并将其输出.需要添加tokens=*
,因为它将读取所有输出.
Where the second batch file reads the output of the first one and outputs it. The addition tokens=*
is needed as it will then read all the output.
如果有不清楚的地方,可以随时提出问题:)
Feel free to ask questions if something is not clear :)
这篇关于使一个批处理文件从另一个批处理文件获取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!