中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-08 20:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [讨论]关于 Call 的问题 查看 780 回复 4
楼 主 [讨论]关于 Call 的问题 发表于 2008-06-03 10:11 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
积分 558
发帖 172
注册 2003-02-09 00:00
23年会员
UID 881
性别 男
来自 江苏
状态 离线
call :test
ECHO After "call", this wil be executed.

:test
echo Just a test

REM 难道一定要把 :test 放在最后或者使用 Goto语句才能不执行下边语句

echo I don't want this to be executed inside "test", it should be executed after "call".
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
2 发表于 2008-06-03 10:42 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
积分 3,687
发帖 1,467
注册 2005-08-08 12:00
21年会员
UID 44210
状态 离线
call :test
ECHO After "call", this wil be executed.
goto :eof

:test
echo Just a test
goto :eof

echo I don't want this to be executed inside "test", it should be executed after "call".
3 发表于 2008-06-03 11:11 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105
发帖 1,276
注册 2008-03-08 13:00
18年会员
UID 112398
性别 男
状态 离线
1 :: echo I don't want this to be executed inside "test", it should be executed after "call".
2 rem echo I don't want this to be executed inside "test", it should be executed after "call".
3 设立个条件,加在前面:

set /a n+=1&call :test
ECHO After "call", this wil be executed.
goto :eof
:test
echo Just a test
if %n% lss 2 goto :eof
echo I don't want this to be executed inside "test", it should be executed after "call".

以上代码当call :test被执行一次以上后,每次将执行后面的echo I don't want this to be executed inside "test", it should be executed,第一次时不会执行。
批处理之家新域名:www.bathome.net
4 发表于 2008-06-03 14:15 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
积分 558
发帖 172
注册 2003-02-09 00:00
23年会员
UID 881
性别 男
来自 江苏
状态 离线
谢谢各位, 这证实了"Call" 调用标签的局限性.

不像高级语言中可以用 END Procedure 之类来表示一个子程序的结束.

看来只能用GOTO 来解决, 或者放在最后.

三楼技巧虽好, 但似乎脱离了本贴的主题. 有点杀鸡用牛刀的感觉. 不过说实话, 我编不出类似三楼的代码, 如果我从来没看过这样的代码.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
5 发表于 2008-06-03 18:13 ·  中国 上海 电信
初级用户
★★
积分 160
发帖 81
注册 2006-07-27 17:52
20年会员
UID 59377
性别 男
状态 离线
没意思
call 有它的作用,goto也有它的作用
论坛跳转: