Page 1 of 1

[SOLVED] Console output to text file missing entries.

Posted: 03 Aug 2020 13:17
by PAB
Good evening everyone.

I have this cmd . . .

Code: Select all

for /f "tokens=*" %%i in ('wevtutil.exe el') do echo "%%i" & wevtutil.exe cl "%%i" & wevtutil.exe cl System
When I run it, it outputs the list and any ERRORS to the console, great so far!

I put that in a separate .bat file and called it from another .bat file because I just wanted to create a .txt file on the desktop rather than having it run in the console . . .

Code: Select all

call "%~dp0bin\Events.bat" > "%userprofile%\desktop\Event.txt"
The .txt file is great, EXCEPT the errors are shown on the screen [ ONLY the errors btw ], but NOT in the .txt file.
I added 2>nul to stop the errors showing in the console, but they still don't show in the .txt file.

I basically want everything that gets output to the console as per the first piece of code, including the errors, output to a .txt file.

Thanks in advance.

Re: Console output to text file missing entries.

Posted: 03 Aug 2020 13:26
by Squashman
The basic syntax to append STDOUT and STDERR to a file.
command >> file 2>&1

Re: Console output to text file missing entries.

Posted: 03 Aug 2020 17:54
by PAB
Squashman wrote:
03 Aug 2020 13:26
The basic syntax to append STDOUT and STDERR to a file.
command >> file 2>&1
Brilliant, thank you, it is appreciated!