Board logo

标题: IF中能嵌套CALL命令? [打印本页]

作者: linmilin     时间: 2007-5-31 11:24    标题: IF中能嵌套CALL命令?
IF中嵌套CALL命令,为何CALL命令不能得到正确执行。请高手指教。谢谢!
问题如下:


setlocal enabledelayedexpansion
color 0A
set targerpath=c:\temp
set fyyyymm=2007.05
:id_loop
echo.
set id=
set /p id=input the id number:
if "!id!" == "" (
cls
echo error - the id is null¡
echo.
goto id_loop
) else (
pushd !targerpath!\!fyyyymm!
if not exist "!id!" (
md !id!
) else (
popd
echo the !id! exist¡
echo.
:rade_loop
set rade=
set /p rade=renamedeltreeexit
if "!rade!" == "" (
cls
echo error - select the string¡
pause>nul
goto rade_loop
) else (
call :!rade! 2>nul || call :p REM 在这里选择e或r时,CALL命令均调用:P 的这段代码
pause>nul
goto :eof
:p
echo error - select the string!
goto :rade_loop
goto :eof
:e
echo this is exit!
goto :eof

:r
echo this is rename!
goto :eof
)
)
)


Last edited by linmilin on 2007-5-31 at 09:33 PM ]

作者: stornager     时间: 2007-5-31 15:26
call :!rade! 用法错误,应该是call:rade_loop
set /p rade=renamedeltreeexit应该改为set rade=renamedeltreeexit 吧

Last edited by stornager on 2007-5-31 at 03:34 PM ]

作者: linmilin     时间: 2007-5-31 15:53
Originally posted by stornager at 2007-5-31 03:26 PM:
call :!rade! 用法错误,应该是call:rade_loop
set /p rade=renamedeltreeexit应该改为set rade=renamedeltreeexit 吧

Last edited by stornager on 2007-5-31 at 03:34 PM ]


第一:
set /p rade=renamedeltreeexit
这一句是用于与用户进行互动,可以让用户选择条件。

第二:
:rade_loop
此循环是当用户选择的条件非程序设置的条件时进行跳转的。
CALL调用的是以下部分程序:
call :!rade! 2>nul || call :p
pause>nul
goto :eof
:p
echo error - select the string!
goto :rade_loop
goto :eof
:e
echo this is exit!
goto :eof

:r
echo this is rename!
goto :eof

作者: wudixin96     时间: 2007-5-31 16:06
@echo off
:rade_loop
set rade=
set /p rade=renamedeltreeexit
if "%rade%"=="" (
cls
echo error - select the string
pause>nul
goto rade_loop
) else (
call :%rade% 2>nul||call :p
pause>nul
goto :eof
:p
echo error - select the string!
goto :rade_loop
goto :eof
:e
echo this is exit!
pause>nul
goto :eof

:r
echo this is rename!
pause>nul
goto :eof
)


在偶运行看来。就call :%rade%出问题。个人认为没必要启用延迟

作者: linmilin     时间: 2007-5-31 21:20
Originally posted by wudixin96 at 2007-5-31 04:06 PM:
@echo off
:rade_loop
set rade=
set /p rade=renamedeltreeexit
if "%rade%"=="" (
cls
echo error - selec ...



此程序为程序的一部分;要启用延迟.

作者: wudixin96     时间: 2007-5-31 22:02
call :!rade! 2>nul || call :p

第一call后, errorlevel变量变成1,即失败。所以会调用第二个call

作者: linmilin     时间: 2007-6-1 08:56
确实是这样,但就是找不出为什么会导致这样的问题。
从程序上说,程序是没问题的。但就是得不到想要的结果。
请不吝赐教。