Board logo

标题: 在for中使用goto的问题 [打印本页]

作者: techwise     时间: 2007-12-4 10:49    标题: 在for中使用goto的问题
for /f "delims=" %%i in (ip.txt) do (
ping %%i -n 1 -l 50 -w 2 | find ""Ping request could not find host %%i." /i
if not errorlevel 1 echo %%i 计算机名不正确 >> error.log & goto end
.......
echo %%i 执行命令成功 >>d:\result\succeed.log
:end
echo %%i )

每次执行的时候以遇到计算机名称不正确的,就直接跳出for循环了不执行后面的了,请高位高手帮忙看一下是什么问题??

作者: huahua0919     时间: 2007-12-4 11:03
ping n 5=127.1>nul

作者: techwise     时间: 2007-12-4 11:07
Originally posted by huahua0919 at 2007-12-4 11:03 AM:
ping n 5=127.1>nul

2楼的是什么意思?

作者: techwise     时间: 2007-12-4 11:08
Originally posted by techwise at 2007-12-4 11:07 AM:

2楼的是什么意思?


你的意思是延时,那添加到那儿??

作者: mkd     时间: 2007-12-4 12:12
作者: techwise     时间: 2007-12-4 12:37
Originally posted by mkd at 2007-12-4 12:12 PM:
http://www.cn-dos.net/forum/viewthread.php?tid=19152&fpage=1&highlight=errorlevel

Last edited by mkd on 2007-12-4 at 12:13 PM ]

这位老兄的意思是if语句的问题??
当我把语句写成下面的样式时就没出错了:
for /f "delims=" %%i in (ip.txt) do (
ping %%i -n 1 -l 50 -w 2 | find ""Ping request could not find host %%i." /i
if not errorlevel 1 (
echo %%i 计算机名不正确 >>d:\result\error.log
) else (
echo %%i 执行命令成功 >>d:\result\succeed.log)
)
那说明是goto语句的问题,我在论坛中也找到了一个相似的帖子:
http://www.cn-dos.net/forum/viewthread.php?tid=27964&fpage=1&highlight=for
我也怀疑是for中使用goto语句的问题,我发出来是想高手解释一下是为什么,有没有办法解决??

作者: mkd     时间: 2007-12-4 19:52
是我看錯了。抱歉啊~