Hi Peter,
I have a method using the FindWindow API that works for a batch file but
with anything more complicated (e.g a VB program with events etc) it's not
that good due to the two applications demanding processing power. However if
you are just running a batch file it might work for you.
The code works by looking for a handle on the cmd window. Unfortunately this
means that the Mapinfo thread repeatedly calls the API call, which has a
performance hit. However it might be okay for what you need.
Note the code loops twice - first loop looks for the cmd window.
2nd window keeps looping till the cmd window has closed (batch file has run)
'the api declaration is:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer
'the code is:
Dim intAppRunning as integer
Dim ClassName, Title, Batch as string
Batch = 'path to your .bat file here
ClassName = "ConsoleWindowClass"
Title = "C:\WINNT\System32\cmd.exe" ' NT/2000 version
'or use ' XP version...: Title = "C:\WINDOWS\System32\cmd.exe"
'you can probably search your system for these values if you prefer
' first run your batch program - called by path/filename
Run Program Batch
'Calls Win32 API: Waits for Batch to finish running
Do
intAppRunning = FindWindow(ClassName, Title)
' handle is 0 till it is found
Print "Getting Window Handle ..."
Loop While intAppRunning = 0
Do
intAppRunning = FindWindow(ClassName, Title)
' handle is > 0 till batch stops running
Print "Running Batch..."
Loop While intAppRunning > 0
Print "Batch finished"
Note to list: Does anyone have a better (less looping..??) method that
doesn't rely on making repeated API calls?
Cheers,
Dominic
-----Original Message-----
From: Doyle, Peter W [mailto:[EMAIL PROTECTED]
Sent: 16 March 2004 04:52
To: [EMAIL PROTECTED]
Subject: MI-L Mapbasic & Windows API question
Greetings List,
I am running a windows batch file from within Mapbasic.
Does anybody know of a Windows API call that will return an error level code
when a batch file has finished running in the command window.
What I am trying to do is have the Mapbasic code wait till the batch file
has finished running and then continue on,
as it is relies on the output of the batch file to exist before continuing.
I remember seeing something about a Tick timer somewhere, but this is
probably not the solution as the time the batch file takes to run can vary
considerably fom toime to time.
Any help appreciated as allways
Regards
Peter Doyle
Geographical Analysis & Data
Telstra, Mobile Network Services
Service Management
ph: 07 38871128
fax: 07 32364383
Level 4
171 Roma Street Brisbane 4000
[EMAIL PROTECTED]
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10881
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10887