Save output and exit code of command to files on windows
Posted
by
poncha
on Server Fault
See other posts from Server Fault
or by poncha
Published on 2012-12-01T22:50:17Z
Indexed on
2012/12/02
5:07 UTC
Read the original article
Hit count: 592
I want to run a command and save its output and its exit code, in different files.
Here's what i am doing:
cmd.exe /C command 1> %TEMP%\output.log 2> %TEMP%\error.log && echo %ERRORLEVEL% > %TEMP%\status || echo %ERRORLEVEL% > %TEMP%\status
If i don't do output redirection (into %TEMP%\output.log
and/or %TEMP%\error.log
), then exit code is saved just fine.
However, when i run the line as shown above more than once (just get back to previous line in command prompt and rerun it), i get 0 in %TEMP%\status
regardless of the real exit code.
What am i missing? Or maybe there's a better way of doing this?
© Server Fault or respective owner