Computer Hope

Microsoft => Microsoft Windows => Windows NT/2000 => Topic started by: TJ-III on May 17, 2011, 09:24:02 AM

Title: echo command return code
Post by: TJ-III on May 17, 2011, 09:24:02 AM
1. Does the echo command return an error/exit code?
2. Is there any documentation anywhere that describes the return codes from echo?
3. Does an error from a pipe redirection of echo's output return an error code?
4. Is there any documentation anywhere that describes the return codes from pipe redirection?

Any help, suggestions, or pointers to reference material accepted with thanks.
Title: Re: echo command return code
Post by: Geek-9pm on May 18, 2011, 10:55:56 PM
You need to explain what you want.
The 'echo' feature is part of the script used by the command processor. It is not a function or procedure that called by a program.
Have you read this?
http://www.computerhope.com/xdoseror.htm
Title: Re: echo command return code
Post by: Salmon Trout on May 19, 2011, 12:38:31 AM
As Geek says, it would be interesting to know what you are aiming for.

Errorlevels are a bit of a mess. This batch shows what I mean.

Code: [Select]
@echo off
color 00
echo bad:   %errorlevel%
ver >nul
echo ok:    %errorlevel%
fc/? >nul
echo weird: %errorlevel%
set/? >nul
echo ret:   %errorlevel%
(set foo=)
echo ret:   %errorlevel%
rem Did not reset the errorlevel?
set foo >nul
echo ret:   %errorlevel%
rem So why did this one set the errorlevel?
echo hello | find "egg
echo ret:   %errorlevel%

Output (Win 7 64 bit SP1)

Code: [Select]
bad:   1
ok:    0
weird: -1
ret:   -1
ret:   -1
Environment variable foo  not defined
ret:   1
FIND: Parameter format not correct
ret:   2







Title: Re: echo command return code
Post by: Salmon Trout on May 19, 2011, 02:27:52 AM
The example with FIND I showed above is with a malformed (deliberately wrong) FIND syntax (missing quote after search string). The errorlevel (2) is that set by FIND. Otherwise it would have been 0 (string found) or 1 (string not found).