I do not know the wintee
command, but I think I can help you with the redirection issue:
Instead of test_name.bat [parameters] 2>&1 | wtee log.txt
, you should write the following:
(test_name.bat [parameters] 2>&1 1> con) | wtee log.txt
This writes the text at STDOUT to the console, redirects the data at STDERR to STDOUT, which is in turn passed to the wtee
command.
Note that the console displays all original STDOUT before any STDERR data, because the former is displayed immediately, while the latter is passed through wtee
. With pure redirection hacks it is not possible to preserve the original order which the data was returned with. If you insist on that, you need to use a tool other than wintee
which has got the required capabilities. Edit: In particular, the pipe is the bottleneck, because there is only one channel, namely STDIN, where it passes data to. So if you insist on STDOUT and SRDERR data to be displayed in the original order while saving the data of one stream to a file, you have no other choice but to modify the script test_name.bat
and to avoid piping.
I am trying to explain that using the command dir ":"
on the left side of the pipe, which produces output at both STDOUT and STDERR (because of the invalid path ":"
):
D:\Data> dir ":"
Volume in drive D has no label.
Volume Seriel Number is 0000-0000
Directory of D:\Data
File Not Found
The File Not Found
message appears at STDERR, whereas the rest appears at STDOUT (you can prove that by redirecting like 2> nul
or 1> nul
to dismiss either of the streams).
On the right side of the pipe, I am using the command find /V ""
, which simply passes all data it receives at STDIN through and displays it on the console:
D:\Data> dir ":" | find /V ""
File Not Found
Volume in drive D has no label.
Volume Seriel Number is 0000-0000
Directory of D:\Data
The changed order of the console output illustrates what happens: STDERR is displayed immediately, whereas STDOUT is first passed through the pipe before being displayed.
Now let us apply the redirection 2>&1
from your command line:
D:\Data> (dir ":" 2>&1) | find /V ""
Volume in drive D has no label.
Volume Seriel Number is 0000-0000
Directory of D:\Data
File Not Found
This redirects STDERR to STDOUT, so the original STDOUT data together with the redirected ones are piped through. Replacing find /V ""
by (> nul find /V "")
proves that the right side of the pipe really receives all of the data.
Now let us add the 1> con
portion, which constitutes an explicit redirection of STDOUT to the console:
D:\Data> (dir ":" 2>&1 1> con) | find /V ""
Volume in drive D has no label.
Volume Seriel Number is 0000-0000
Directory of D:\Data
File Not Found
The output contains all of the original data. Again replacing find /V ""
by (> nul find /V "")
proves that this time, the right side of the pipe truly only recieves the File Not Found
message, which was originally present at STDERR, but the STDOUT data are not piped through.
Just a side-note:
If you want to do something like wintee
with pure batch-file, things become very complicated -- see this example...