%errorlevel%在Windows XP中不起作用.但它可以在Windows7中使用 [英] %errorlevel% doesn't work in Windows XP. But it works in Windows7
问题描述
%errorlevel%在WindowsXP中不起作用.
%errorlevel% doesn't work in WindowsXP.
据我所知,当错误发生时,%errorlevel%设置为1或更高的值,如果没有错误,它将设置为0.
As I know when an error occurs %errorlevel% set 1 or above value, and if there is no error it will set 0.
但是,即使没有错误,%errorlevel%也为1. 而且我将%errorlevel%设置为0,即使错误%errorlevel%的门槛为0.
But, even though there is no error, %errorlevel% is 1. And I set %errorlevel% 0, even there is an error %errorlevel% is sill 0.
我认为操作系统在XP中不会更改%errorlevel%.
I think OS doesn't change %errorlevel% in XP.
在Win7中,它完全可以正常工作.
In Win7 it work totally.
@echo off
setlocal enabledelayedexpansion
call dir
echo errorlevel=%errorlevel%
REM expected errorlevel=0 but 1
call dor
echo errorlevel=%errorlevel%
REM expected errorlevel=1
set errorlevel=0
call dor
echo errorlevel=%errorlevel%
REM expected errorlevel=1 but 0
但是如果错误级别1()看起来可行.
But if errorlevel 1 () looks work.
推荐答案
一些示例:
@ECHO OFF &SETLOCAL
echo errorlevel=%errorlevel%
call dir >nul
echo errorlevel=%errorlevel%
输出:
output:
errorlevel=0
errorlevel=0
@ECHO OFF &SETLOCAL
echo errorlevel=%errorlevel%
call dor
echo errorlevel=%errorlevel%
输出:
output:
errorlevel=0
'dor' is not recognized as an internal or external command,
operable program or batch file.
errorlevel=1
@ECHO OFF &SETLOCAL
::set errorlevel=0 illegal operation!
set test=1
set test
echo errorlevel=%errorlevel%
call dor
echo errorlevel=%errorlevel%
输出:
output:
test=1
errorlevel=0
'dor' is not recognized as an internal or external command,
operable program or batch file.
errorlevel=1
set errorlevel
不是合法命令.如果需要设置错误级别的系统环境变量,请使用常规命令执行此操作.
set errorlevel
is not a legal command. If you need to set the errorlevel system environment variable, do this with a usual command.
@ECHO OFF &SETLOCAL
::set errorlevel=1 illegal operation!
set test
echo errorlevel=%errorlevel%
call dir >nul
echo errorlevel=%errorlevel%
输出:
output:
Environment variable test not defined
errorlevel=1
errorlevel=0
这篇关于%errorlevel%在Windows XP中不起作用.但它可以在Windows7中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!