I want to do something like:
echo %errorlevel% > error.txtwhich would save in error.txt:
%errorlevel% 0 1 Answer
If you actually want to write the twelve characters% e r r o r l e v e l %(as opposed to writing the numeric error level), use the command
echo %%errorlevel%%Redirection works as normal.
However, note that
echo %%errorlevel%% > error.txtwill actually write the thirteen characters% e r r o r l e v e l % ,
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 10