联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off & setlocal enabledelayedexpansion call :callee /n p1 /i p2 /x p3 pause goto :EOF :callee _param1 _param2 _param3 /n /i /x set index=1 set options= :loop call set param=%%~%index% if defined param ( if "%param:~0,1%"=="/" ( set options=%options% %param% shift /%index% ) else ( set /a index+=1 ) goto :loop ) echo %1 %2 %3 %options% goto :EOF
@echo off & setlocal enabledelayedexpansion call :callee /n p1 /i p2 /x p3 pause goto :EOF :callee _param1 _param2 _param3 /n /i /x goto :adjust :adjust_finished echo %1 %2 %3 %options% goto :EOF :adjust set index=1 set options= :loop call set param=%%~%index% if defined param ( if "%param:~0,1%"=="/" ( set options=%options% %param% shift /%index% ) else ( set /a index+=1 ) goto :loop ) goto adjust_finished
@REM 假设参数在9个以内 @echo off & setlocal enabledelayedexpansion call :callee /n p1 /i p2 /x p3 pause goto :EOF :callee _param1 _param2 _param3 /n /i /x if not defined calling call :adjust callee %* if defined called ( set calling= set called= goto :EOF ) echo %* goto :EOF :adjust _caller %* set calling=true set caller=%1 shift set index=1 set params= set options= :loop call set param=%%~%index% if defined param ( if "%param:~0,1%"=="/" ( set options=%options% %param% shift /%index% ) else ( set /a index+=1 ) goto :loop ) set index-=1 for /l %%i in (1,1,%index%) do call set params=!params! %%%%i call :%caller% %params%%options% set called=true goto :EOF
@REM 结合26933062(感谢!)的代码对上贴中的第二种方法做了改进 @echo off & setlocal enabledelayedexpansion call :callee /n "hello world" /i "hello script" 1 2 3 4 5 6 7 8 9 10 pause goto :EOF :callee :: 下面的两句是调用调整参数次序的代码,不能少。 :: 看起来还是有点怪-_-|| call :adjust %0 called %* if defined called goto :EOF echo %* goto :EOF :adjust _caller _flag_called %* if defined calling ( set calling= goto :EOF ) else ( set calling=true ) set args= set options= set index=1 for %%i in (%*) do ( set param=%%~i if "!param:~0,1!"=="/" ( set options=!options! %%i ) else ( if !index! GTR 2 ( set args=!args! %%i ) set /a index+=1 ) ) set ^%2= call %1 %args%%options% set ^%2=true goto :EOF
@echo off&setlocal enabledelayedexpansion set str=/n /i /x for %%a in (%str%) do set .%%a=%%a call :loop /n p1 /i p2 /x p3 echo !num! pause :loop for %%a in (%*) do if not defined .%%a set num=!num! %%a set num=!num! !str! goto :eof 小楼一夜听春雨 2008-07-20 13:18
@echo off call :loop /n p1 /i p2 /x p3 echo %num% pause rem 低下的代码就是你说的“模块”上面的就是调用方法, rem 全局中只要不使用 num 作为变量名就不会和你的代码发生任何冲突。 :loop setlocal enabledelayedexpansion set var1=&set "var2=" for %%a in (%*) do ( set "var=%%a" if not "!var:~0,1!"=="/" (set var1=!var1! %%a) else set "var2=!var2! %%a" ) set "var=!var1! !var2!" endlocal&set "num=%var%"&goto :eof 小楼一夜听春雨 2008-07-20 13:50
Originally posted by 26933062 at 2008-7-20 14:00: 将参数中以 / 开头的,全部放到最后。
Originally posted by 26933062 at 2008-7-20 14:41: 不明白你到底要干什么
@echo off call :callee /n "hello world" /i "hello script" goto :EOF :callee ::在这里调用调整参数次序的代码 ::我希望在这里能用%1访问到"hello world",用%2访问到"hello script"。 ::以/打头的是选项,选项可以通过一个环境变量提供给我。或者可以通过%1~%9访问。 goto :EOF