如何将用户的字符串从批处理文件输入到环境变量中 [英] How to input a string from user into environment variable from batch file
问题描述
我想提示用户输入一些详细信息,然后将其用作命令行参数.
I want to prompt the user for some input detail, and then use it later as a command line argument.
推荐答案
您可以将 set
与 /p
参数一起使用:
You can use set
with the /p
argument:
SET/P 变量=[promptString]
/P 开关允许您将变量的值设置为一行输入由用户输入.读取前显示指定的 promptString输入行.promptString 可以为空.
The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.
所以,只需使用类似的东西
So, simply use something like
set /p Input=Enter some text:
稍后您可以将该变量用作命令的参数:
Later you can use that variable as argument to a command:
myCommand %Input%
但请注意,如果您的输入可能包含空格,则引用它可能是个好主意:
Be careful though, that if your input might contain spaces it's probably a good idea to quote it:
myCommand "%Input%"
这篇关于如何将用户的字符串从批处理文件输入到环境变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!