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

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

问题描述

我想提示输入一些细节的用户,然后再使用它作为一个命令行参数。

I want to prompt the user for some input detail, and then use it later as a command line argument.

推荐答案

您可以使用设置 / P> / code >参数:

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.

所以,只要使用类似

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天全站免登陆