Problems with batch file not halting on error

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems with batch file not halting on error

跳至解决方案
2,835 次查看
italiandoh
Contributor III
Hello,
I am using Codewarrior for Freescale MC9S12X family via batch file and not using the IDE.
I successfully created the batch file for compiling, linking and so on and it works OK, but with a problem. In case of a error during execution of compiler, the batch file in unable to detect this error and stop the process. This way we are forced to wait for the compilation of all files before stopping the process.
Of course we use the tool "Piper.exe" to capture the output of the various tools and save it to file and print it on screen.
Here's a sample of the batch file code :

for %%c in (%CTARGETS%) do (call %COMPILER_PATH%\piper.exe %COMPILER% %%c %COMPILER_OPTIONS%
                            IF %ERRORLEVEL% NEQ 0 goto error_label
                            echo.
                            echo.
                            echo.)

We use this for loop in the batch file to compile all the *.c source code files. But it seems like that, in case of compiler errors, the ERRORLEVEL variable is not set, so the for loop is not interrupted.
I guess that the problem is that piper.exe does not report any errors even if chc12.exe returned them.
Has anyone experienced such a problem ?
If anyone knows a possible solution for this, please let me know.
Thanks in advance and best regards,

Matteo
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,056 次查看
italiandoh
Contributor III

FYI, I solved the problem in my batches by checking for the creation of err.log after the compiling of each source file.

See this example:

 

echo.
for /R %CSOURCES_PATH% %%c in (*.c) do (call "%COMPILER_PATH%\piper.exe" %COMPILER% "%%c" %COMPILER_OPTIONS%
                            IF %ERRORLEVEL% NEQ 0 goto error_label
                            IF EXIST %PROJECT_ROOT%\err.log goto compiler_fault
                            echo.
                            echo.
                            echo.)

Bye,

 

Matteo

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,057 次查看
italiandoh
Contributor III

FYI, I solved the problem in my batches by checking for the creation of err.log after the compiling of each source file.

See this example:

 

echo.
for /R %CSOURCES_PATH% %%c in (*.c) do (call "%COMPILER_PATH%\piper.exe" %COMPILER% "%%c" %COMPILER_OPTIONS%
                            IF %ERRORLEVEL% NEQ 0 goto error_label
                            IF EXIST %PROJECT_ROOT%\err.log goto compiler_fault
                            echo.
                            echo.
                            echo.)

Bye,

 

Matteo

0 项奖励
回复