|
-
May 24th, 2007, 05:19 AM
#1
Thread Starter
Addicted Member
[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"?
-
May 24th, 2007, 12:32 PM
#2
Thread Starter
Addicted Member
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.
-
May 24th, 2007, 02:20 PM
#3
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|