How to input a string from user into environment v

2020-02-18 11:08发布

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

2条回答
做个烂人
2楼-- · 2020-02-18 11:47

A rather roundabout way, just for completeness:

 for /f "delims=" %i in ('type CON') do set inp=%i

Of course that requires ^Z as a terminator, and so the Johannes answer is better in all practical ways.

查看更多
淡お忘
3楼-- · 2020-02-18 11:49

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%"
查看更多
登录 后发表回答