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

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

问题描述

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

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屋!

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