我无法弄清楚为什么Windows 10中没有将值存储在变量中。 我在互联网上搜索没有任何原因无法解决该问题。
@echo off
:start
REM check if there are more then one argumnets
if not "%2" == "" (
echo Too many parameters entered
) ELSE (
REM check if argument one is empty
SETLOCAL ENABLEDELAYEDEXPANSION
if "%1"=="" (
echo "Enter your Name"
SET /P filename=
echo Your Name is "%filename %"
)
if "%filename%"=="" (
echo "empty"
) else (
echo "dat"
)
)
运行此命令时:
Enter your Name
asd
Your Name is
我做错什么了吗?
答案 0 :(得分:2)
这也可能对您有所帮助:
@Echo Off
SetLocal EnableDelayedExpansion
If "%~1"=="" (
Echo No parameter was passed
GoTo EndIt
) Else (
If Not "%~2" == "" (
Echo Too many parameters entered
GoTo EndIt
) Else (
Echo "Enter your Name"
Set /P "filename="
If "!filename!"=="" (
Echo "empty"
) Else (
Echo Your Name is "!filename!"
Echo "dat"
)
)
)
:EndIt
Pause
GoTo :EOF