如何从批处理文件中将用户输入的字符串输入环境变量 [英] How to input a string from user into environment variable from batch file
问题描述
我想提示用户输入一些详细信息,然后再将其用作命令行参数。
您可以使用 set
与 / p
参数:
< >
SET / P变量= [promptString]
将变量的值设置为用户输入的输入行
。在读取
之前显示指定的promptString输入行。 promptString可以为空。
因此,只需使用
set / p Input =输入一些文本:
使用该变量作为命令的参数:
myCommand%输入%
请小心,如果你的输入可能包含空格,这可能是一个好主意:
<$> p $ p>myCommand%Input%
I want to prompt the user for some input detail, and then use it later as a command line argument.
You can use set
with the /p
argument:
SET /P variable=[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屋!