批处理文件if语句不能与cmd一起使用

时间:2014-04-05 20:38:48

标签: c batch-file if-statement

我找到了答案,但没有找到答案。

@echo off
:a
cls
set /p %a% =
if %a% == 1 goto b
goto c
:b
echo.
echo worked
pause
:C
echo.
echo dident work
pause

我设置了一个= 1,并且说goto命令此时是意外的。任何帮助都会很棒

更改

确定它已发生变化并出现新问题。现在当a = 1时,它总是转到c而不是b

@echo off
:a
cls
set /p a = 
if "%a%" == "1" goto b
goto c
:b
echo.
echo worked
pause
:C
echo.
echo wierd
pause

3 个答案:

答案 0 :(得分:0)

改变这个:

set /p %a% =

set /p a=

if %a% == 1 goto b

if "%a%" EQU "1" goto b

答案 1 :(得分:0)

@echo off&cls
set /p a=Enter a number : 
if "%a%" EQU "1" goto:b
echo dident work
exit/b

:b
echo Result = 1

答案 2 :(得分:0)

@echo off  
echo.  
set /p a=  
echo.  
if %a%==1 goto b  
if not %a%==1 goto c  
:b  
echo worked  
echo.  
pause  
exit  
:c  
echo dident work  
echo.  
pause  
exit