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:
  1. ProcessId = Shell("c:\a.bat", 1)
  2.     hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
  3.  
  4.     Do
  5.  
  6.         Call GetExitCodeProcess(hProcess, exitCode)
  7.         DoEvents
  8.    
  9.     Loop While exitCode <> 0
  10.  
  11.     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"?