加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 在批处理文件中捕获错误(7-zip)

发布时间:2020-12-13 23:22:12 所属栏目:Windows 来源:网络整理
导读:我有一个批处理文件,我在其中执行以下行来列出存档的内容: "Program Files7-Zip7z.exe" l "Backup Google Docs.7z" 存档故意损坏. cmd.exe显示如下: 如何在代码中捕获此错误? 任何程序的退出代码都存储在批处理脚本的%ERRORLEVEL%变量中. 从7-zip手
我有一个批处理文件,我在其中执行以下行来列出存档的内容:
"Program Files7-Zip7z.exe" l "Backup Google Docs.7z"

存档故意损坏.

cmd.exe显示如下:

如何在代码中捕获此错误?

任何程序的退出代码都存储在批处理脚本的%ERRORLEVEL%变量中.

从7-zip手册:

7-Zip returns the following exit codes:

Code Meaning 
0 No error 
1 Warning (Non fatal error(s)). For example,one or more files were locked by some other application,so they were not compressed. 
2 Fatal error 
7 Command line error 
8 Not enough memory for operation 
255 User stopped the process

所以:你可以这样做:

"Program Files7-Zip7z.exe" l "Backup Google Docs.7z"
if errorlevel 255 goto:user_stopped_the_process
if errorlevel 8 goto:not_enough_memory
if errorlevel 7 goto:command_line_error
if errorlevel 2 goto:fatal_error
if errorlevel 1 goto:ok_warnings

注意,如果errorlevel N检查%ERRORLEVEL%是否大于或等于N,那么您应该按降序排列它们.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读