Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Negative ERRORLEVEL

1,095 views
Skip to first unread message

BoB Teijema

unread,
Feb 4, 2002, 8:20:34 AM2/4/02
to
If I run the following:

winmsd %COMPUTERNAME% /a /f
ECHO %ERRORLEVEL%

then the output is

-1

What does a negative ERRORLEVEL mean?


Ritchie

unread,
Feb 4, 2002, 10:19:55 AM2/4/02
to
"BoB Teijema" <bob.t...@informa.com> wrote in message
news:3c5e8aa3$0$227$4d4e...@read.news.nl.uu.net...

Your machine's ****ed :)

I don't know... I got 2 and 0 on NT4 and W2K respectively. Was there
sufficient disk space? write access?

--
Ritchie

Matthias Paul

unread,
Feb 4, 2002, 12:43:33 PM2/4/02
to
On 2002-02-04, Bob Teijema wrote:

> ECHO %ERRORLEVEL%
>
> then the output is
>
> -1
>
> What does a negative ERRORLEVEL mean?

Simply that it is interpreted as a signed value, where the most
significant bit indicates the sign:

cleared = positive
set = negative

Under DOS, the errorlevel is a BYTE, so -1 means 255, -2 = 254,
-3 = 253 and so on. But you seem to be using some kind of Windows,
where the width of the errorlevel variable may be different.

Using negative errorlevels is nothing mysterious and sometimes
even convenient: In programming, positive result codes are often
used to indicate various success or non-fatal error conditions,
negative numbers to specify that a serious error occured. It´s
just a convention which may make a piece of code more readable.
At least the DR-DOS COMMAND.COM support signed values without
problems, for example:

IF ERRORLEVEL -1 GOTO xyz


Greetings,

Matthias

--
<mailto:Matthi...@post.rwth-aachen.de>; <mailto:mp...@drdos.org>
http://www.uni-bonn.de/~uzs180/mpdokeng.html; http://mpaul.drdos.org


Al Dunbar

unread,
Feb 4, 2002, 11:49:34 PM2/4/02
to

"Matthias Paul" <Matthi...@post.rwth-aachen.de> wrote in message
news:a3mhpg$c3f$1...@nets3.rz.RWTH-Aachen.DE...

> On 2002-02-04, Bob Teijema wrote:
>
> > ECHO %ERRORLEVEL%
> >
> > then the output is
> >
> > -1
> >
> > What does a negative ERRORLEVEL mean?
>
> Simply that it is interpreted as a signed value, where the most
> significant bit indicates the sign:
>
> cleared = positive
> set = negative
>
> Under DOS, the errorlevel is a BYTE, so -1 means 255, -2 = 254,
> -3 = 253 and so on. But you seem to be using some kind of Windows,
> where the width of the errorlevel variable may be different.
>
> Using negative errorlevels is nothing mysterious and sometimes
> even convenient: In programming, positive result codes are often
> used to indicate various success or non-fatal error conditions,
> negative numbers to specify that a serious error occured.

True enough, however, those of us coming from the pre-32-bit windows/dos
environments still intrinsically expect the errorlevel to be in the range 0
to 255. I just did a test and found that, indeed, it will accept positive
and negative numbers, apparently stored in 32 bits, based on the overflow.

But this begs the next question: You know that if you are using IF
ERRORLEVEL n goto:whereever, in the old days you would start with the
highest expected values, and work down, as "IF ERRORLEVEL 3" tests (or did
in the 16bit days) for a value of 3 OR GREATER. So if the value being tested
is 0, is -1 considered less or greater?

/Al

Rik D'haveloose

unread,
Feb 7, 2002, 3:33:12 PM2/7/02
to
Al Dunbar wrote
> Matthias Paul wrote

> > On 2002-02-04, Bob Teijema wrote:

unquoted from previous:
winmsd

> > > ECHO %ERRORLEVEL%
> > > then the output is
> > > -1
> > >
> > > What does a negative ERRORLEVEL mean?
> >
> > Simply that it is interpreted as a signed value, where the most
> > significant bit indicates the sign:

==8<


> True enough, however, those of us coming from the pre-32-bit
windows/dos
> environments still intrinsically expect the errorlevel to be in the
range 0
> to 255. I just did a test and found that, indeed, it will accept
positive
> and negative numbers, apparently stored in 32 bits, based on the
overflow.

please define 32-bit windows, my W98 version does not have "WINMSD"
???

==8<


> > At least the DR-DOS COMMAND.COM support signed values without
> > problems, for example:
> >
> > IF ERRORLEVEL -1 GOTO xyz

Also, which vesion of DR-dos ? (i expect 7.0 ??, as 6.0 does not mention
that).

Anyway, again some result from not using the correct NG (or not paying
attention with multi-posting and removing some), IMHO, as %errorlevel%
is only known on NT and such, afaik.

Please, try to follow netetiquette, and use correct NG and remove NG
where it is inapropriate also, which is in this case (for what i know as
amb reader):
news:alt.msdos.batch.NT, IIUIC, and avoid confusing non-users of these
OS versions (and for your own profit, if using such OS, as obtaining
more correct answers is more likely there).

--
KISSTUF Greetings from Rumbeke
Belgium

Al Dunbar

unread,
Feb 7, 2002, 8:09:42 PM2/7/02
to

"Rik D'haveloose" <brol.d...@xs4all.be> wrote in message
news:a3uonc$nrb$5...@news1.xs4all.nl...

> Al Dunbar wrote
> > Matthias Paul wrote
> > > On 2002-02-04, Bob Teijema wrote:
>
> unquoted from previous:
> winmsd
>
> > > > ECHO %ERRORLEVEL%
> > > > then the output is
> > > > -1
> > > >
> > > > What does a negative ERRORLEVEL mean?
> > >
> > > Simply that it is interpreted as a signed value, where the most
> > > significant bit indicates the sign:
> ==8<
> > True enough, however, those of us coming from the pre-32-bit
> windows/dos
> > environments still intrinsically expect the errorlevel to be in the
> range 0
> > to 255. I just did a test and found that, indeed, it will accept
> positive
> > and negative numbers, apparently stored in 32 bits, based on the
> overflow.
>
> please define 32-bit windows, my W98 version does not have "WINMSD"
> ???

Two apologies. First, (in NT and up) the errorlevel variable appears to be
stored internally as a 16bit (not 32bit) quantity. Second apology, see
below...

> ==8<
> > > At least the DR-DOS COMMAND.COM support signed values without
> > > problems, for example:
> > >
> > > IF ERRORLEVEL -1 GOTO xyz
>
> Also, which vesion of DR-dos ? (i expect 7.0 ??, as 6.0 does not mention
> that).
>
> Anyway, again some result from not using the correct NG (or not paying
> attention with multi-posting and removing some), IMHO, as %errorlevel%
> is only known on NT and such, afaik.

2nd apology continued: I am sorry that I did not notice the NG's to which my
reply went. Perhaps I assumed that, since an earlier poster was refering to
%ERRORLEVEL%, that the entire thread was intrinsically NT (2k, xp) in
nature.

/Al


Charles Dye

unread,
Feb 7, 2002, 8:30:26 PM2/7/02
to
"Rik D'haveloose" <brol.d...@xs4all.be> wrote in message news:<a3uonc$nrb$5...@news1.xs4all.nl>...

> Anyway, again some result from not using the correct NG (or not paying


> attention with multi-posting and removing some), IMHO, as %errorlevel%
> is only known on NT and such, afaik.

Not at all; the DR DOS shell, COMMAND.COM, supports the %ERRORLEVEL%
pseudo-variable, as does 4DOS. It's not an NT-specific technique.

--
Charles Dye ras...@highfiber.com

Matthias Paul

unread,
Feb 8, 2002, 11:23:13 AM2/8/02
to
On 2002-02-07, "Rik D'haveloose" <brol.d...@xs4all.be> wrote:

>>> At least the DR-DOS COMMAND.COM support signed values without
>>> problems, for example:
>>>
>>> IF ERRORLEVEL -1 GOTO xyz
>
> Also, which vesion of DR-dos ? (i expect 7.0 ??, as 6.0 does
> not mention that).

Well, I am usually *very* specific in version numbering,
up to the point where it can make a text unreadable... ;-)
Now getting complaints when being lax, I should better
stick to that habit, it seems... ;->

Literally speaking there was neither a product named
"DR-DOS 7.0" nor "DR-DOS 6.0". When I refer to DR DOS
(without hyphen) I always mean "before Novell DOS 7",
when I refer to "DR-DOS" (with hyphen) I usually mean
the releases after 1997-12, when the unloved hyphen
was introduced (with the sole exception of EZ-DOS 3.41,
an early OEM version of DR DOS 3.41 ;-).

It愀 a bit difficult to be consistent in writing,
because there have been so many names for basically
the same product line (with some small side-lines).

To be exact, the %ERRORLEVEL% and %ERRORLVL% variables were
introduced with DR-OpenDOS 7.02 in 1997-12, but because almost
noone has this specific release, you can think of it as being
introduced with DR-DOS 7.02+. %ERRORLVL% (a 3-digit value with
leading zeros) existed much earlier in the multi-user series
of the product, and Novell愀 NetWare client had an %ERROR_LEVEL%
or %ERRORLEVEL% variable for a very long time, which was
documented in the NetWare, Personal NetWare 1.0, and Novell DOS 7
documentation.

The support of negative values in IF ERRORLEVEL works at least
since Novell DOS 7 (1994-03), and as such is documented in
NWDOSTIP.TXT in MPDOSTIP.ZIP (see signature). It was probably
supported much earlier - right now I惴 too lazy to look this up,
but I can, if this would prove to be important for you.
I think, it also works with MS-DOS/PC DOS COMMAND.COM, at
least it is not withdrawn as invalid syntax under MS-DOS 7.10
COMMAND.COM, but I惻l leave it to others to play with this.

> Anyway, again some result from not using the correct NG (or not paying
> attention with multi-posting and removing some), IMHO, as %errorlevel%
> is only known on NT and such, afaik.

??? Well, the fact, that Bob Teijema observed the evaluation and display
of negative errorlevels suggests the existance of a signed vs. unsigned
bug in the number formatting routine of the command line interpreter
(a quite typical mistake in C) or at least an errorlevel width different
from 8 bits, and therefore it was clear to me that this could not be
the DR-DOS COMMAND.COM, hence my Windows comment in my original reply.

Nonetheless, I think the issue is interesting and very much on-topic
for DOS users (also in a.m.b.), because the DR-DOS COMMAND.COM
provides this as well. However, ECHO %ERRORLEVEL% gives *positive*
values there, that is:

IF ERRORLEVEL -1 ECHO %ERRORLEVEL%

would (at least for DOS) correctly display "255" not "-1" just like

IF ERRORLEVEL 255 ECHO %ERRORLEVEL%

would do.

Rik D'haveloose

unread,
Feb 10, 2002, 5:09:11 PM2/10/02
to
Al Dunbar wrote
> "Rik D'haveloose wrote

> > Al Dunbar wrote
> > > Matthias Paul wrote
> > > > On 2002-02-04, Bob Teijema wrote:
==8<

> > > > > What does a negative ERRORLEVEL mean?
==8<

> Two apologies. First, (in NT and up) the errorlevel variable appears
to be
> stored internally as a 16bit (not 32bit) quantity. Second apology, see

i'm not seeking apologies, only trying to help avoid confusion for
lesser (?) knowledgable readers in the NG (AMB) i'm following, and which
i consider some netetiquette behaviour to consider by posters and
replyers. Nothing more.... (unless perhaps that users, only aware of
more recent OS's also become aware that they most likely should not use
NG's for older OS'es)

> 2nd apology continued: I am sorry that I did not notice the NG's to
which my
> reply went.

Sometimes this also happens here with me, because too much focusing on
the problem itself.
And i assume also that it is normal that a reader of another NG does not
know the topic of the (not read, crossposted) NG. I only wanted to
inform those less-knowledgable/experienced readers, soo they become
aware of version differences...(and possible, unintented, OT questions
and/or unusable solutions...) (Myself i like it, when someone else
confirms that it does not work/not exists on the OS version i use, takes
away doubt why i did not find it...:-)

> Perhaps I assumed that, since an earlier poster was refering to
> %ERRORLEVEL%, that the entire thread was intrinsically NT (2k, xp) in
> nature.

or DR-dos, 4dos (and alike :-)

Anyway, my apoligies also, because i have a feeling that AMB is misused
by some people, and too easily considered the last-resort solution
general problem solving group, (or commercial alike promoting group) as
long as one includes some batch (or script) referring item, even if i
have not any 'authority' to define the on topic issue, and only seek
batch knowledge there.

--
TUF Greetings from Rumbeke
Belgium


0 new messages