Monday, March 23, 2009

How to redirect cmd output to both screen and file

Hello there! After many frustrating google searches & trials found a way how to redirect command line output to both screen & a file. But you would need to install Cygwin for this since a unix command Tee is needed in our case. This way redirects both stdout & stderr to both screen & file

1. Install cygwin ( google cygwin it is easy to find)
2. Add path of cygwin correctly to system path vairable
ex. path = %PATH%;C:\cygwin\bin\
3. Execute your command or batch file the following way
C:\>echo hello 2>&1 | tee file.log
C:\>mybatchfile.bat 2>&1 | tee file.log

No comments: