Most of you know the classic redirect syntax:
myprogram > output.txt
But this does not capture error messages, which still end up in the console. In order to capture those, too, you need this:
myprogram 1> output.txt 2>&1
Source: Redirecting Error Messages from Command Prompt: STDERR/STDOUT