如何从批处理文件中将用户输入的字符串输入环境变量 [英] How to input a string from user into environment variable from batch file

查看:101
本文介绍了如何从批处理文件中将用户输入的字符串输入环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提示用户输入一些详细信息,然后再将其用作命令行参数。

解决方案

您可以使用 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屋!

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