标题: [文件操作] 批处理goto命令不会直接跳转? [打印本页]
作者: qwe777 时间: 2011-3-6 17:23 标题: 批处理goto命令不会直接跳转?
以下代码为什么会跳转到:1之前还好运行 start "" /b %0 1???
- @echo off
- if "%1"=="1" goto :%1
-
- start "" /b %0 1
- ping -t 127.1
-
- :1
- pause >nul
- exit
复制代码
作者: CrLf 时间: 2011-3-6 21:08
如果是标准环境下双击运行的bat,%1的值是空的,自然不满足跳转条件
作者: qwe777 时间: 2011-3-6 22:31
但start的语句没有完全运行完,又会跳转回if 语句???-
- C:\Documents and Settings\Administrator\桌面>if "" == "1" goto :
- C:\Documents and Settings\Administrator\桌面>start "" /b "C:\Documents and Setti
- ngs\Administrator\桌面\新建 文本文档.bat" 1
- C:\Documents and Settings\Administrator\桌面>ping -t 127.1
- C:\Documents and Settings\Administrator\桌面>if "1" == "1" goto :1
- C:\Documents and Settings\Administrator\桌面>pause 1>nul
- Pinging 127.0.0.1 with 32 bytes of data:
- Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
- Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
复制代码
[ 本帖最后由 qwe777 于 2011-3-6 22:37 编辑 ]
作者: Commander 时间: 2011-3-6 23:07
- if "%1"=="1" goto :%1
-
- start "" /b %0 1
- echo I am first pause
- pause
-
- :1
- echo I am second pause
- pause
复制代码
- if "%1"=="1" goto :%1
-
- call %0 1
- echo I am first pause
- pause
-
- :1
- echo I am second pause
- pause
复制代码
作者: CrLf 时间: 2011-3-6 23:09
运行的时候实际执行的是:- @echo off
- if ""=="1" goto :
- start "" /b %0 1
- ping -t 127.1
- if "1"=="1" goto :1
- start "" /b %0 1
- pause >nul
- exit
- pause >nul
- exit
复制代码
作者: qwe777 时间: 2011-3-7 00:00
if的语句不是运行完了吗,为什么还会运行第二遍。
还有"%1"第一次是为空,而第二次却是为1/???
小弟比较笨,请问有哪位高手能详细都解一下啊???
- if "%1"=="1" goto :%1
-
- start "" /b %0 1
- echo I am first pause
- pause
-
- :1
- echo I am second pause
- pause
复制代码
作者: caruko 时间: 2011-3-7 01:06
你把 start /b ,/B 开关去掉。
然后仔细看一下运行过程。
作者: qwe777 时间: 2011-3-7 18:18
为什么"%1"第一次是为空,而第二次却是为1/???
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |