I have a simple health check script for checking status of windows share drives listed below.
I am getting the desired output when the command works. However, when there is an error, I do not get output in the output file. I have looked at STDOUT and STDERR as a possible solution, but I am not able get this to work yet.
Can anyone please help me with this code.
@echo off
echo START > results.txt
for /f %%s in (server_list.txt) do (
echo %%s >> results.txt
for /f "delims=" %%n in ('net use \\%%s') do (
echo %%s - %%n >> results.txt 2> err.txt
)
)
The output file looks like this.
START
server1
server1 - The command completed successfully.
server2
server2 - The command completed successfully.
However, there is nothing in the err.txt file. I have made sure to put some incorrect entries in file server_list.txt to get a few errors for testing. The error output is displayed in the command line window instead of being printed to the err.txt file.