[RESOLVED] Catching errorlevel from a batch file
I know this is possible by using the GetExitCodeProcess API, the problem with it is that it just catches the code of the ending command... for example, a batch file with this code:
Code:
@echo off
copy c:\dummy.jpeg c:\
The function catches the errorlevel correctly, but if I add "echo errorlev = %ERRORLEVEL%" the GetExitCodeProcess returns a 0 as the last line isn't generating any error...
I've tried catching the exit code doing a loop this way:
vb Code:
ProcessId = Shell("c:\a.bat", 1)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, exitCode)
DoEvents
Loop While exitCode <> 0
CloseHandle hProcess
But it only gets the exitCode = 259, which is the corresponding one to the process still being active...
Is this possible without having to resort to something like "echo %ERRORLEVEL% > errors.txt"?
Re: Catching errorlevel from a batch file
Well, notice some hours ago that I can force the exit code at any moment by doing simply "exit n", so it's just a matter of checking the ERRORLEVEL value each time to see if some error was generated.
Re: [RESOLVED] Catching errorlevel from a batch file
If echo errorlev = %ERRORLEVEL% doesn't throw an error, the exit error of the batch process is 0. There's only 1 error level for a program, and that's the one it sets when it exits. You can save error levels locally (in the batch process) and force an exit level based on a previous error, even though the process has since completed a few further steps with no error.