Skip to main content
Added generic warning about `echo something > somefile`.
Source Link

If you actually want to write the twelve characters %errorlevel% (as opposed to writing the numeric error level), use the command

echo %%errorlevel%%

Redirection works as normal.

However, note that

echo %%errorlevel%% > error.txt

will actually write the thirteen characters %errorlevel% , including the space (from before the >).  “Obviously” you can fix that by saying

echo %%errorlevel%%> error.txt

(leaving out the space before the >), but this is regarded as unaesthetic and hard to read.  Another way, that might be considered to be “prettier”, is

(echo %%errorlevel%%) > error.txt

If you actually want to write the twelve characters %errorlevel% (as opposed to writing the numeric error level), use the command

echo %%errorlevel%%

Redirection works as normal.

If you actually want to write the twelve characters %errorlevel% (as opposed to writing the numeric error level), use the command

echo %%errorlevel%%

Redirection works as normal.

However, note that

echo %%errorlevel%% > error.txt

will actually write the thirteen characters %errorlevel% , including the space (from before the >).  “Obviously” you can fix that by saying

echo %%errorlevel%%> error.txt

(leaving out the space before the >), but this is regarded as unaesthetic and hard to read.  Another way, that might be considered to be “prettier”, is

(echo %%errorlevel%%) > error.txt
Source Link

If you actually want to write the twelve characters %errorlevel% (as opposed to writing the numeric error level), use the command

echo %%errorlevel%%

Redirection works as normal.