如何使用 if 语句和输入在批处理文件中调用另一个批处理文件?
How do you call another batch file in a batch file with if statements and inputs?
在提问之前先问候大家。无论如何,我在这里有一部分批处理文件代码,我想知道为什么每次输入“1”或“2”时它都会说语法不正确然后它会退出。我整晚都在寻找它,但找不到任何东西。我用不同的版本替换了 if else 语句,但其中 none 可以工作 xD。我想知道你们是否可以帮助我,我想提前感谢你们以防我忘记。
这是代码。
set /p ch=[]:
if %ch%==1(
goto login
)
if %ch%==2(
goto register
)
:login
call lxer.bat
exit
:register
call rxer.bat
exit
所以问题是:
It won't call the batch files lxer.bat / rxer.bat
(These batch files are in correct directories/at the same folder already)
It says something about Syntax and then it would directly close.
if
中的(
之前必须有space,否则cmd
将(
分组到要比较的字符串中。结果是 if string == stringcontaining(
和 cmd
说得好,如果那样,那又怎样?
确保字符串存在也是一个想法。如果您只是按 Enter 响应 set p
,则变量保持不变,因此如果尚未设置,cmd
会看到 if == string...
并且会反对。
通常的方式是if "%ch%"=="2" (
我喜欢这样放一个dynamic menu from http://www.dostips.com
描述:
This simple menu framework parses itself for batch labels of certain
signature and lists them as menu items. The self-parsing feature makes
the menu generic. New menu items can be inserted by adding new
function blocks without changing the menu infrastructure.
@echo off
Title Example of a dynamic Menu
:menuLOOP
Color 0A & Mode con cols=55 lines=10
echo(
echo( ====================Menu====================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do (
echo %%A %%B )
echo(
echo( ============================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::*************************
:menu_[1] login
cls
echo(
echo login & pause
call lxer.bat
exit /b
::*************************
:menu_[2] register
cls
echo(
echo register & pause
call rxer.bat
exit /b
::*************************
你也可以看看
在提问之前先问候大家。无论如何,我在这里有一部分批处理文件代码,我想知道为什么每次输入“1”或“2”时它都会说语法不正确然后它会退出。我整晚都在寻找它,但找不到任何东西。我用不同的版本替换了 if else 语句,但其中 none 可以工作 xD。我想知道你们是否可以帮助我,我想提前感谢你们以防我忘记。
这是代码。
set /p ch=[]:
if %ch%==1(
goto login
)
if %ch%==2(
goto register
)
:login
call lxer.bat
exit
:register
call rxer.bat
exit
所以问题是:
It won't call the batch files lxer.bat / rxer.bat (These batch files are in correct directories/at the same folder already) It says something about Syntax and then it would directly close.
if
中的(
之前必须有space,否则cmd
将(
分组到要比较的字符串中。结果是 if string == stringcontaining(
和 cmd
说得好,如果那样,那又怎样?
确保字符串存在也是一个想法。如果您只是按 Enter 响应 set p
,则变量保持不变,因此如果尚未设置,cmd
会看到 if == string...
并且会反对。
通常的方式是if "%ch%"=="2" (
我喜欢这样放一个dynamic menu from http://www.dostips.com
描述:
This simple menu framework parses itself for batch labels of certain signature and lists them as menu items. The self-parsing feature makes the menu generic. New menu items can be inserted by adding new function blocks without changing the menu infrastructure.
@echo off
Title Example of a dynamic Menu
:menuLOOP
Color 0A & Mode con cols=55 lines=10
echo(
echo( ====================Menu====================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do (
echo %%A %%B )
echo(
echo( ============================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::*************************
:menu_[1] login
cls
echo(
echo login & pause
call lxer.bat
exit /b
::*************************
:menu_[2] register
cls
echo(
echo register & pause
call rxer.bat
exit /b
::*************************
你也可以看看