Solved

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

Posted on 2003-12-05
13
630 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

789 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