mirror of
https://github.com/cosinekitty/astronomy.git
synced 2025-12-25 00:29:45 -05:00
In many of my Windows batch files, I used the following
construct to detect failures:
do_something
if errorlevel 1 (
echo.An error occurred in do_something
exit /b 1
)
I discovered that it is possible for a Windows program
to exit with a negative integer error code.
This causes the above construct to miss the failure
and the batch file blithely continues.
So I have replaced that construct with
do_something || (
echo.An error occurred in do_something
exit /b 1
)
This way, if the command exits with any nonzero error,
we correctly detect it as a failure.
20 lines
530 B
Batchfile
20 lines
530 B
Batchfile
@echo off
|
|
setlocal EnableDelayedExpansion
|
|
|
|
for %%x in (msbuild.exe) do (set msbuild=%%~$PATH:x)
|
|
if not defined msbuild set msbuild=c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
|
|
if not exist "!msbuild!" (
|
|
echo.ERROR: cannot find msbuild.exe
|
|
exit /b 1
|
|
)
|
|
|
|
echo.Building C code
|
|
|
|
set OUTDIR=%cd%\bin\
|
|
"!msbuild!" windows\generate\generate.sln /p:Configuration=Release /v:quiet /nologo /p:clp=Summary || (
|
|
echo.BUILD FAILED.
|
|
exit /b 1
|
|
)
|
|
|
|
echo.Build succeeded.
|
|
exit /b 0 |