c++ – Why is the wrong% errorlevel% being returned?


I use such an old time-mem utility to measure the execution time of a command from the command line. This is just a C ++ project, the main code is here .

I start checking, for the test I run timemem 7z some-err-str . An error is clearly displayed, shows code 7, this code is returned. But in a batch file, if you print echo% errorlevel% right after this command, I get 0.

The batch file itself:

timemem 7z some-err-str
rem timemem возвращает 7. А выводится на экран 0
echo %errorlevel%

In general, it behaves the same as the similar utility ptime.

Why, I have no explanation. And most importantly, how can you fix it?


The problem was nonsense. In c ++ code , the info () function always returned 0. Namely, the result of this function determines the return code of the program. Changed at the very end info ()

return 0;


return dwExitCode;

It became correct. It was also confusing that the correct return code was displayed in the console, but 0 was actually returned.

Scroll to Top