Solved

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

Posted on 2003-12-05
13
631 Views
Last Modified: 2011-04-14
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
0
Comment
Question by:JamesSmithIsTaken
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 10

Expert Comment

by:ADSaunders
ID: 9882930
Hi JamesSmithIsTaken,
file.exe
if %errorlevel%==0 then goto end
echo "program failed"
:end

Regards .. Alan
0
 
LVL 1

Author Comment

by:JamesSmithIsTaken
ID: 9883055
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
0
 
LVL 17

Expert Comment

by:inthedark
ID: 9883169
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883225
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
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 200 total points
ID: 9883267
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%
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883348
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
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9883627
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883869
That's what I'm saying...on my system it doesn't.  It immediately returns with 0.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883871
Thanks for the response.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9883890
Must be a difference between ME and NT/2000/XP.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9883909
James

What OS do you use?
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9883918
>>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
0
 
LVL 1

Author Comment

by:JamesSmithIsTaken
ID: 9886323
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question