当我输入带有空格的东西时,set / p会崩溃

时间:2014-07-25 14:12:18

标签: windows batch-file crash

 set /p name= Enter the NAME :

 if [%name%]==[] goto input_failed

当我输入一些名称gani_(其中_是空格)时,我的脚本崩溃了。

2 个答案:

答案 0 :(得分:1)

试试这个 -

set /p "name= Enter the NAME :"

echo.%name%

if "%name%"=="" goto input_failed

示例输出

D:\>draft.bat

D:\>set /p "name= Enter the NAME :"
Enter the NAME :gane

D:\>echo.gane
gane

D:\>if "gane " == "" goto input_failed

干杯,G

答案 1 :(得分:0)

set "name="
set /p "name= Enter the NAME :"

然后以下任何一项都会进行测试

 if "%name%"=="" goto input_failed
 if not defined name goto input_failed