Tip - piping all stsadm messages to a text file

Published 05 October 07 07:00 PM

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 http://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 http://blogs.msdn.com/markarend/ !

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About Stian Kirkeberg

Stian Kirkeberg - Senior Consultant, Microsoft Consulting Services

This Blog

Syndication

Page view tracker