My batch file is prematurely terminating when I run this in a cmd.exe that is NOT an MSVC development command shell.
msbuild /version | find "Microsoft (R) Build Engine version 16" >nul
echo did I get here?
if errorlevel 1 goto no_msbuild
I never get to the if errorlevel line, so I added the echo did I get here? line, and I don't get that either.
Here's the output when I run the .bat file (I removed the @echo off):
Wed 09/07/2022 10:37:49
D:\temp> msbuild /version | find "Microsoft (R) Build Engine version 16" 1>nul
'msbuild' is not recognized as an internal or external command,
operable program or batch file.
Wed 09/07/2022 10:37:49
D:\temp>
It works fine when I run it in a VS2019 cmd shell (if errorlevel 1 test is false, i.e. errorlevel is 0, so find worked) and a VS2008 cmd (if errorlevel 1 is true, so find failed)
EDIT: I eliminated the whole msbuild command/path issue, incorporating @mofi possible solution and came up with the following:
xyzzy 2>nul | find "abc"
echo hello
if errorlevel 1 goto no_xyzzy
The .bat file still terminates prematurely and never executes the echo hello even with the stderr redirection to nul.