1.

Solve : DOS Batch Cmds?

Answer»

Curiosty: in the parameters for
copy extract.exe %ramdrive% > NUL
what is the > NUL parameter

Now to the pertinent question
How to display (ECHO) errorlevel returned from a call?
ECHO %errorlevel% ? which does not seem to work {actually i guess the return from 'ECHO' would be displayed.

IF errorlevel 255 {goto echo255, :echo255, echo 255}
IF errorlevel 254 ...Welcome to the CH forums.

Quote from: kosmith

Curiosty: in the parameters for
copy extract.exe %ramdrive% > NUL
what is the > NUL parameter

> NUL directs output, which would normally be displayed, to a non-existent device. So used with Copy the "1 files copied" and some error messages will not be seen.

For the rest of your here is the guru ROB Van der W on the subject.

When you post please, as a minimum, tell us what Operating System you are using.

Thanks & good luckThanks !!!
Already read Vander w on error return.
OS is Win98 DOS (6.2?)
Still have a question, maybe I did not ask the correct question(s).

1. If a bat, exe or com returns an errorlevel, how do I display it?
set errnum=
someexe.exe /switches
set errnum=%errorlevel%
echo %errnum%
??

2. When an exe or com returns a string value (like a function return) what (local or global) is it returned to?
%1 ? %2 ?
How do I access the return value to parse it?
Sorry for the naivety, but I searched everwhere all day and can't seem to find the therory.
You guys are the last bastion of "Hope" !
Thanks againRe: 1. Quote from: Rob Van Der W
@ECHO OFF
IF ERRORLEVEL 1 SET ERRORLEV=1
IF ERRORLEVEL 2 SET ERRORLEV=2
IF ERRORLEVEL 3 SET ERRORLEV=3
IF ERRORLEVEL 4 SET ERRORLEV=4



IF ERRORLEVEL 254 SET ERRORLEV=254
IF ERRORLEVEL 255 SET ERRORLEV=255
ECHO ERRORLEVEL = %ERRORLEV%

Also see the section headed "In DOS for the rest of us, we can use FOR loops to determine the errorlevel:" in the Rob Van Der W site.
--------------------------------------------------------------------------------------------

Quote from: kosmith
ECHO %errorlevel% which does not seem to work

Not surprising - here's another quote from the Rob van der W site:

Quote from: Rob van der W
However, Windows NT 4 and later make it easy by storing the latest errorlevel in the environment variable ERRORLEVEL:
ECHO.%ERRORLEVEL%
will display the errorlevel.

The %errorlevel% environment variable is only available in Win.NT4 and later, you are running Win.98.
------------------------------------------------------------------------------------------------

Re: 2. Sorry, I don't know but believe this is program dependent. The answer may or may not be found in the program documentation. Perhaps someone else will join in with better info.

Good luck

Dusty,
Thanks for the help ! ! !
I think the light has finally come on.
Now I'll go visit the sponsors websites.
Great Forum, please keep up the great work.
K.O. SmithQuote from: Dusty on January 21, 2008, 12:48:49 AM
Re: 1. Quote from: Rob Van Der W
@ECHO OFF
IF ERRORLEVEL 1 SET ERRORLEV=1
IF ERRORLEVEL 2 SET ERRORLEV=2
IF ERRORLEVEL 3 SET ERRORLEV=3
IF ERRORLEVEL 4 SET ERRORLEV=4
...

It's been a while, but I seem to remember - - shouldn't testing for errorlevel be done in descending order?
Quote from: WillyW
It's been a while, but I seem to remember - - shouldn't testing for errorlevel be done in descending order?

Yes, that is also explained on the Rob van der W site I posted. Here is another extract from that site, the underlining is mine:

Quote from: Rob van der W
The safest way to use errorlevels for all DOS versions is the reverse order check.
Start checking the highest errorlevel that can be expected, then check for the one below, etcetera:

IF ERRORLEVEL 255 GOTO Label255
IF ERRORLEVEL 254 GOTO Label254



IF ERRORLEVEL 2 GOTO Label2
IF ERRORLEVEL 1 GOTO Label1
GOTO Label0

:Label255
(commands to be executed at errorlevel 255)
GOTO End

etc.....

Thanks for your interest.Quote from: Dusty on January 21, 2008, 01:19:39 PM

Yes, that is also explained on the Rob van der W site I posted. Here is another extract from that site, the underlining is mine:

Quote from: Rob van der W
The safest way to use errorlevels for all DOS versions is the reverse order check.
Start checking the highest errorlevel that can be expected, then check for the one below, etcetera:

IF ERRORLEVEL 255 GOTO Label255
IF ERRORLEVEL 254 GOTO Label254
...

hmm... interesting. I'll have to try to remember to check that out.

I find it curious that he used the term "safest". As I remember it, it wouldn't work at all if not in descending order.

In other words, a line like:
if errorlevel 5 some_command
would really mean, ' if the current errorlevel is equal to, or greater than 5, then do some_command '.

So I'm THINKING that if they were in ASCENDING order, like in the first example,
a line like ' if errorlevel 1 ..." would be true with ANY of the errorlevels between 255 and 2 also.

Maybe it's been too long since I've played with this stuff.....

Quote from: WillyW
n other words, a line like:
if errorlevel 5 some_command
would really mean, ' if the current errorlevel is equal to, or greater than 5, then do some_command '.

So I'm thinking that if they were in ascending order, like in the first example,
a line like ' if errorlevel 1 ..." would be true with ANY of the errorlevels between 255 and 2 also.

That's also on the Rob van der W site - here's the quote:Quote from: Rob van der W
IF ERRORLEVEL construction has one strange feature, that can be used to our advantage: it returns TRUE if the return code was equal to or higher than the specified errorlevel.

This means most of the time we only need to check IF ERRORLEVEL 1 ... and this will return TRUE for every non-zero return code.

Yep, a very strange feature indeed but that's typical of the world of programmers





So he is saying that that the code of his that you first quote/posted doesn't work.

That sure seems odd to me. I don't see why he published it.Hold on a second guys.....
The correct (often published) is decending order.
But this works just fine:
FINDRAMD

IF ERRORLEVEL 255 GOTO NoRamDrive
IF NOT ERRORLEVEL 3 GOTO NoRamDrive
echo %errorlevel%

IF ERRORLEVEL 3 SET RAMDRIVE=C:
IF ERRORLEVEL 4 SET RAMDRIVE=D:
IF ERRORLEVEL 5 SET RAMDRIVE=E:
IF ERRORLEVEL 6 SET RAMDRIVE=F:

...

IF ERRORLEVEL 24 SET RAMDRIVE=X:
IF ERRORLEVEL 25 SET RAMDRIVE=Y:
IF ERRORLEVEL 26 SET RAMDRIVE=Z:

IF ERRORLEVEL 27 GOTO NoRamDrive

ECHO RAMdisk drive letter is %RAMDRIVE%
GOTO End

This may become an issue after the errorlevel is higher then 99 (or maybe 200)
It would depend upon the internal storage (should be a single byte 0xFF)

I have tested both, but on on Win98, XP, and 6.21 DOS....................
Wanna bet the issues were back in DOS 3.1 ?


Discussion

No Comment Found