When I run the command:
if exist file.txt (echo yes) else (echo no) > "output.txt" 2>&1
in a command prompt, if 'file.txt' doesn't exist, a file 'output.txt' is created reading 'no', whereas if 'file.txt' does exist, 'yes' is output to the console window and the file 'output.txt' isn't even created. I also executed a batch file:
if exist file.txt (echo yes) else (echo no) > "output.txt" 2>&1
pause
and the result was the same, when 'file.txt' does exist 'yes' only appears in the console window. What's the reason, and how do I get all the output to redirect to 'output.txt' consistently?