Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need help with writing a batch file that returns an error code to another application (app1).
My batch file is called by another application, when my batch file runs, it calls a VBS Script. This script on completion returns an error code of either 1 or 1 or 2.
My batch file should capture this return code, and return it to the main application (app1)
The problem I have is that my batch file returns an error level 0 to the main application.
This is a snippet of my code
--------------
c:\winnt\system32\cscript.exe d:\ABC.vbs %1if errorlevel 2 goto errorthree
if errorlevel 1 goto errorone:errorthree
ECHO.
ECHO DTF file transfer process failure
ECHO.
goto end:errorone
ECHO.
ECHO DTF file failed to transfer successfully
ECHO.
goto end:end
---------If I type in echo %errorlevel%, it returns zero, even when the vbs file returned an error code of 2 or 1.
Any help will be useful.
Thanks

First of all, let's clear something up: the errorlevel is not an environment variable. On NT systems, the environment variable %errorlevel% is automatically set to the errorlevel's value. If you change the value of the environment variable %errorlevel%, the value of errorlevel will not change because of that.
If your VBS script returns a certain errorlevel, it will not be changed unless some other program or command change it. No command on that piece of code you posted can change the errorlevel, not that I'm aware of. However, some other command from another part of the code might be changing it.
Generally, external commands (such as FIND, FC, XCOPY, RENAME) will change the errorlevel. In Windows NT4-, it seems the REM command can also change the errorlevel, but the comment syntax "::comment" won't.
You may save the errorlevel on a variable right after the script, run the rest of commands, which could change the errorlevel, then restate the errorlevel. However, I'm unsure of what method to use to set the errorlevel to a certain value via batch file...
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

Even Iam facing the same problem.
Iam trying to execute a copy command and checking the error level.My command is
copy c:\temp\file.txt d:\application >nul 2>error_logerror_log file is created in spite of the succesful operation.
I dont understand that when Y error stream is called and file created.
This error_log file has no data and 0 bytes.
Reagards
Srihari

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |