Calling a VB exe from a batch, and detecting it's success or failure from the batch

I need to call blah.exe from a batch file.  And from this batch file I need to know whether or not blah was succesful.

Thanks
LVL 1
JamesSmithIsTakenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ADSaundersCommented:
Hi JamesSmithIsTaken,
file.exe
if %errorlevel%==0 then goto end
echo "program failed"
:end

Regards .. Alan
JamesSmithIsTakenAuthor Commented:
Thanks, that's the batch file side of the question.

How do I return the errorlevel from inside the application?

The only way I know to exit the VB application is with End
inthedarkCommented:
A simple way is create a file from your batch like this

echo Starting >myfile.txt

And have then VB program kill the file before the end...

Kill "MyFile.txt"

So in your batch file you can test for the file

If Exist MyFile.txt goto SystemCrash
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
On my system, if file.exe is a VB App, then the batch file returns before the app is finished and/or closed.

Idle_Mind
EDDYKTCommented:
Try this

in VB form

Option Explicit
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call ExitProcess(1)
End Sub


in bat file
c:\temp\project1.exe
echo %errorlevel%

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
EDDYKT,

I have used that API successfully before and trapped the exit code from other programs without trouble.  However, on my system, just launching the executable from the batch file is seen as success and the batch file continues on with the next line with exit code 0 before the app has actually finished.

Have you tried trapping the code from a batch file on your system?  I am using WinME.

Idle_Mind
EDDYKTCommented:
I did try what I posted in Win 2000 Server and it works

If I replace to  Call ExitProcess(100)

I will see 100 from printout

>>the batch file continues on with the next line with exit code 0 before the app has actually finished.


No it wait till the [project1.exe finished
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
That's what I'm saying...on my system it doesn't.  It immediately returns with 0.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Thanks for the response.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Must be a difference between ME and NT/2000/XP.
EDDYKTCommented:
James

What OS do you use?
EDDYKTCommented:
>>Must be a difference between ME and NT/2000/XP

for sure, they are total different from me and nt/2000/XP professional or higher
JamesSmithIsTakenAuthor Commented:
I teseted on XP.. it works

for some reason the batch file knows to wait for %errorlevel% if you put %userprofile% there instead I think it wouldn't break.

Thanks for the answers guys
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.