- 帖子
- 508
- 积分
- 1490
- 技术
- 87
- 捐助
- 0
- 注册时间
- 2008-7-17
|
通过以下测试可以确认
||并不是根据errorlevel来判断是否执行右侧的语句
Microsoft Windows [版本 5.2.3790]
(C) 版权所有 1985-2003 Microsoft Corp.
C:\Documents and Settings\Administrator>xx
'xx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\Documents and Settings\Administrator>echo %errorlevel%
9009
C:\Documents and Settings\Administrator>echo not set errorlevel
not set errorlevel
C:\Documents and Settings\Administrator>echo %errorlevel%
9009
C:\Documents and Settings\Administrator>echo not set errorlevel || echo not run
not set errorlevel
C:\Documents and Settings\Administrator>xx || echo run
'xx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
run
C:\Documents and Settings\Administrator>
根据以下测试可以证明
||会在左侧代码未成功完成时置errorlevel为1
C:\Documents and Settings\Administrator>xx
'xx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\Documents and Settings\Administrator>echo %errorlevel%
9009
C:\Documents and Settings\Administrator>echo not set errorlevel || echo not run
not set errorlevel
C:\Documents and Settings\Administrator>echo %errorlevel%
9009
C:\Documents and Settings\Administrator>xx || echo run
'xx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
run
C:\Documents and Settings\Administrator>echo %errorlevel%
1
根据以下测试可以证明
||是在右侧命令执行之前置errorlevel,而非整条语句执行完成后
C:\Documents and Settings\Administrator>xx
'xx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\Documents and Settings\Administrator>echo %errorlevel%
9009
C:\Documents and Settings\Administrator>xx || if errorlevel 1 if not errorlevel 2 echo errorlevel == 1
'xx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
errorlevel == 1
综合以上论断
可以确认在||在左侧语句未成功完成时
会置errorlevel为1
同时启动执行右侧的语句 |
-
2
评分人数
-
|