Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

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
0
JamesSmithIsTaken
Asked:
JamesSmithIsTaken
  • 5
  • 4
  • 2
  • +2
1 Solution
 
ADSaundersCommented:
Hi JamesSmithIsTaken,
file.exe
if %errorlevel%==0 then goto end
echo "program failed"
:end

Regards .. Alan
0
 
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
0
 
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
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!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
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%
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's what I'm saying...on my system it doesn't.  It immediately returns with 0.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Thanks for the response.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Must be a difference between ME and NT/2000/XP.
0
 
EDDYKTCommented:
James

What OS do you use?
0
 
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
0
 
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
0

Featured Post

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!

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now