Reputation: 31743
Assuming I have the following batch comannd which works as expected.
file1.exe | file2.exe
Now I have the following requirement. - Stderr from file1.exe should be written to a logfile - Stdout and Stderr from file2.exe should be written to a logfile
This works, too
file1.exe 2>>file1.log | file2.exe >>file2.log 2>&1
However, what I really want is to have both outputs in the same file. This fails because file.log
is used by another process
file1.exe 2>>file.log | file2.exe >>file.log 2>&1
Here is a real world example to demonstrate the issue.
echo test 2>>file.log | findstr t 1>>file.log 2>&1
Upvotes: 0
Views: 76
Reputation: 566
If you don't need to execute this task in properly real time, you can also create two different temporary files:
file1.exe 2 >> temp1.log | file2.exe >> temp2.log
And then you can print the second text file to the first one:
echo. >> temp1.log && type temp2.log >> temp1.log
REM "echo." leaves a blank line in the output file
Upvotes: 0
Reputation: 41257
This will pipe all the data to findstr:
echo test 2>&1 | findstr "^" >file.log 2>&1
Upvotes: 0