命令ERRORLEVEL由一批循环执行 [英] Errorlevel of command executed by batch for loop

查看:172
本文介绍了命令ERRORLEVEL由一批循环执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code总是显示为0的错误级别,但是当copy命令外面做了循环命令返回一个非零错误级别。

The following code always displays 0 as the errorlevel, but when the copy command is done outside of the for loop command it returns a non zero errorlevel.

for /f "usebackq delims=" %%x in (`copy x y`) do (
    set VAR=%%x
)
ECHO Errorlevel = %ERRORLEVEL%
ECHO VAR = %VAR%

时有可能获得由循环执行的复制命令的ERRORLEVEL?

Is is possible to get the errorlevel of the copy command executed by the for loop?

推荐答案

我的作品!你只需把错误的DO括号内检查
用含有复制命令(7200行的文本文件;例如:
副本2_97691_Scan.pdf○:\\ DATA \\开发\\敏思\\ PDFScan2 \\ 2011 \\ 4 \\ 2_97691_Scan.pdf)
我可以运行以下批处理文件

it works for me ! You only need to put the error checking within the DO parentheses with a text file containing the copy commands (7200 lines; for example: copy 2_97691_Scan.pdf O:\Data\Dev\Mins\PDFScan2\2011\4\2_97691_Scan.pdf), I can run the following batch file

@echo off

setlocal EnableDelayedExpansion

for /F "delims=" %%I in (CopyCurrentPDFs.txt) do (
%%I
if !errorlevel! NEQ 0 echo %%I>>errorcopy.txt
)

这篇关于命令ERRORLEVEL由一批循环执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆