</> 很多时候编写代码时为了减少代码的重复性以及便于管理整个代码的同步性更新和可利用性,都会使用到的东西——函数模块
如:
-=> ======== 《 不使用函数模块 》 ========
@璐村惂鐢ㄦ埛_000076K馃惥 off
set a=1
if "%a%"=="1" (
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"explorer.exe"') do (echo.%%i)
echo.%cd%
)
if "%a%"=="2" (
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"cmd.exe"') do (echo.%%i)
echo.%cd%
)
if "%a%"=="3" (
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"svchost.exe"') do (echo.%%i)
echo.%cd%
)
pasue
exit
-=> ======== 《 使用函数模块 》 ========
@echo off
set a=1
if "%a%"=="1" call :DEMO "explorer.exe"
if "%a%"=="2" call :DEMO "cmd.exe"
if "%a%"=="3" call :DEMO "svchost.exe"
pause
exit
:DEMO
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"%1"') do (echo.%%i)
echo.%cd%
goto :eof
</> 函数模块也分为可返值和不可返值
如:
-=> ======== 《 不使用函数模块 》 ========
@璐村惂鐢ㄦ埛_000076K馃惥 off
set a=1
if "%a%"=="1" (
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"explorer.exe"') do (echo.%%i)
echo.%cd%
)
if "%a%"=="2" (
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"cmd.exe"') do (echo.%%i)
echo.%cd%
)
if "%a%"=="3" (
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"svchost.exe"') do (echo.%%i)
echo.%cd%
)
pasue
exit
-=> ======== 《 使用函数模块 》 ========
@echo off
set a=1
if "%a%"=="1" call :DEMO "explorer.exe"
if "%a%"=="2" call :DEMO "cmd.exe"
if "%a%"=="3" call :DEMO "svchost.exe"
pause
exit
:DEMO
echo.-= DEMO =-
for /f "delims=" %%i in ('tasklist^|findstr /c:"%1"') do (echo.%%i)
echo.%cd%
goto :eof
</> 函数模块也分为可返值和不可返值