自动批量设置输入变量? [英] Auto set a input variable in batch?

查看:53
本文介绍了自动批量设置输入变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理脚本,问题是我需要文件自动调用并自动输入变量



我需要这样的东西:

< br /> 
::a是一个批处理文件,其主要内容将在此之后< br />
a VAR< br />
:: VAR是需要输入的变量的值< br />



这是a.bat:

< br /> 
cd Temp< br />
echo:a>> save.temp< br />
设置a =< br />
set / p a =:< br />
echo:%a%>> save.temp< br />
echo echo%a%>> bot.temp< br />
echo goto prompt>> bot.temp< br />
cd ..< br />
cd ..< br />
make< br />



我想让它做需要用户输入的变量,我不能把它改成类似

设置a =%othervar%

因为我的整个程序将失败。



如何让值进入而不是用户必须输入?

解决方案

你的代码有很多bug。请考虑这个:

 @ echo off 

define parameter =%1
echo这是第一个:%1
如果%parameter%==set / p parameter =输入参数值:

echo%参数%

暂停





注意:命令行参数是%1,而不是%% 1;没有定义;你应该使用字符串比较,这是运算符'=='。



它对你有帮助吗?



-SA


看看这里:

http://stackoverflow.com/questions/1515965/how-to-input-a-string -from-user-into-environment-variable-from-batch-file [ ^ ]

http://snipplr.com/view/14953/ [ ^ ]







如果你想用输入参数调用另一个批处理文件试试这个:

first.bat

 second.bat   Hello world! 





second.bat

 @ echo  我的路径:%0 
@echo 第一个输入变量: %1
@echo 第二个输入变量:%2
rem 依此类推;)
暂停





在上面的示例中,%1 变量存储文本: Helo world!

这就是你要找的东西吗?



更多关于:在Windows批处理文件中使用变量 [ ^ ]

I have a batch script and the problem is I need the file to automatically call on and automatically input a variable

I need something like this:

<br />
::"a" Is a batch file its main contents will be after this<br />
a VAR<br />
::VAR is a the value of a variable that needs input<br />


this is a.bat:

<br />
cd Temp<br />
echo :a >> save.temp<br />
set a=<br />
set /p a=:<br />
echo :%a% >> save.temp<br />
echo echo "%a%" >> bot.temp <br />
echo goto prompt >> bot.temp<br />
cd..<br />
cd..<br />
make<br />


I want it to do the variable that needs user input, I cant just change it to something like
set a=%othervar%
because my whole program will fail.

How do I make the value go in instead of the user having to type it?

解决方案

You code has a number of bugs. Please consider this:

@echo off

define parameter=%1
echo This is first: %1
if "%parameter%"=="" set /p parameter=Enter parameter value: 

echo %parameter%

pause



Pay attention: command-line parameter is %1, not %%1; there is not "defined"; you should use string comparison, which is the operator '=='.

Does it help you?

—SA


Have a look here:
http://stackoverflow.com/questions/1515965/how-to-input-a-string-from-user-into-environment-variable-from-batch-file[^]
http://snipplr.com/view/14953/[^]


[EDIT #1]
If you want to call another batch file with input parameter try this:
first.bat

second.bat "Hello world!"



second.bat

@echo "path to me: " %0
@echo "first input variable: " %1
@echo "second input variable: " %2
rem "and so on ;)"
pause



In above example %1 variable stores text: "Helo world!"
Is that what you're looking for?

More about: Using variables in windows batch files[^]


这篇关于自动批量设置输入变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆