Tip - piping all stsadm messages to a text file

I just got this great tip from Mark Arend:

Everyone knows that using the  >  operator in DOS will redirect a program's output to a file so it can be examined later, such as:

stsadm -o addsolution -filename MySoln.wsp >output.txt

But if stsadm displays error messages from attempting this operation, they still go to the screen and not into the file!  What gives?  We have to remember that DOS has two standard output devices, stdout and stderr.  The  >  operator redirects stdout only.  Fortunately, we can add another operator that will redirect stderr to stdout so that all messages will go into the output file:

stsadm -o addsolution -filename MySoln.wsp >output.txt 2>&1

>& is a command redirection operator.  Stderr is handle 2, and stdout is handle 1.  Therefore, 2>&1 means redirect stderr to stdout.  Since we've already redirected stdout to output.txt, then all messages will now go into this file.  See https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true for further applications.

Finally, remember that  >>  will append messages from stdout to the specified file instead of overwriting;  >>output.txt 2>&1 works to append all messages and errors.

Also, you should check out Marks blog at https://blogs.msdn.com/markarend/ !