Sorry for not including the MapBasic type and function declarations for this in my previous message. If you want to read more about this (or any Win32 API function) check out the online documentation at msdn.microsoft.com
(eg. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas e/createprocess.asp is the documentation for CreateProcess) Type STARTUPINFO cb As Integer lpReserved As String lpDesktop As String lpTitle As String dwX As Integer dwY As Integer dwXSize As Integer dwYSize As Integer dwXCountChars As Integer dwYCountChars As Integer dwFillAttribute As Integer dwFlags As Integer wShowWindow As Smallint cbReserved2 As Smallint lpReserved2 As Integer hStdInput As Integer hStdOutput As Integer hStdError As Integer End Type Type PROCESS_INFORMATION hProcess As Integer hThread As Integer dwProcessID As Integer dwThreadID As Integer End Type Define NORMAL_PRIORITY_CLASS &H20 Define INFINITE -1 Declare Sub ExecuteAndWait(ByVal cmdLine As String) Declare Function CloseHandle Lib "kernel32" (hObject As Integer) As smallint Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Integer,ByVal dwMilliseconds As Integer) As Integer Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Integer, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Integer, ByVal lpThreadAttributes As Integer, ByVal bInheritHandles As Integer, ByVal dwCreationFlags As Integer, ByVal lpEnvironment As Integer, ByVal lpCurrentDirectory As Integer, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Integer Cheers, Martin > -----Original Message----- > From: Robert Crossley [mailto:[EMAIL PROTECTED] > Sent: Monday, 12 April 2004 07:01 > To: [EMAIL PROTECTED] > Subject: Re: MI-L more on WinExecute and Wait.... (long-winded) > > > THis looks interesting, but do you have all the declarations and defines > required as well? > I'm sure if I searched, I could find them, but i'd imagine you woul have > them handy? > > Process_Information > StartUpInfo > CreateProcessA > NORMAL_PRIORITY_CLASS > WaitForSingleObject > INFINITE > CloseHandle > > r > > On Sun, 11 Apr 2004 18:57:31 +1000, Martin Higham <[EMAIL PROTECTED]> > wrote: > > > This is what I replied to the original message in this thread > (from Peter > > Horsboll Moller). It is _very_ reliable and I use it to > control imut.exe > > from an mbx. I also use these API calls from C++ and they work fine. > > > > > > Someone posted code like it to the list some years ago, but I > don't know > > who > > to credit. > > > > > > Function ExecuteAndWait(cmdLine as string) as integer > > > > Dim nRetVal as integer > > Dim NameOfProc as Process_Information, NameStart as StartUpInfo > > > > NameStart.cb = 256 > > NameStart.dwFlags = 1 > > NameStart.wShowWindow = 0 > > nRetVal = CreateProcessA(0, cmdLine, 0, 0, 1, > NORMAL_PRIORITY_CLASS, 0, > > 0, > > NameStart, NameOfProc) > > nRetVal = NameOfProc.hProcess > > nRetVal = WaitForSingleObject(NameOfProc.hProcess, INFINITE) > > nRetVal = CloseHandle(NameOfProc.hProcess) > > > > End Function > > > > > > > > Hope this helps. > > > > Best Regards, > > > > Martin Higham > > Avantra Geosystems > > > > ph (61 3) 8504 0428 0425-730-428 > > fx (61 3) 9596 7997 > > www.avantra.com.au > > > > > > > > > >> -----Original Message----- > >> From: Mickey Feldman [mailto:[EMAIL PROTECTED] > >> Sent: Friday, 9 April 2004 02:51 > >> To: [EMAIL PROTECTED] > >> Subject: MI-L more on WinExecute and Wait.... (long-winded) > >> > >> > >> > >> My original problem was automated conversion of many files from > >> TAB to SHP as > >> part of a multi-stage conversion (The SHP's were then further > >> converted by a > >> closed app that did not recognize TABs) > >> > >> Several suggestions were: > >> > >> 1) use a command line with the /wait parameter (Bill Thoen) > >> > >> 2) monitor a "sentinel" file - in the last line of the batch > >> file delete the > >> file then while fileexists(sentinel file) do > Application.Processmessages > >> (Trey Pattillo) > >> > >> In my experience these are not a whole answer. My program builds > >> a batch file > >> that looks like this (ignore the line wrap around...): > >> > >> Start "TS2" /wait /b "C:\Program > Files\MapInfo\Professional\UT\IMUT.EXE" > >> usa7200.XXX > >> Start "TS2" /wait /b "C:\Program > Files\MapInfo\Professional\UT\IMUT.EXE" > >> usa720102.XXX > >> Start "TS2" /wait /b "C:\Program > Files\MapInfo\Professional\UT\IMUT.EXE" > >> usa7203.XXX > >> > >> ...followed by many more lines with only the .XXX file changed. > >> XXX is a file > >> build by calling IMUT with generate, etc. (My data is not X rated, I > >> just > >> found it important to choose an extension that was not associated > >> with some > >> other program.) > >> > >> When this is run, task manager shows as many as 15 instances > of IMUT.EXE > >> running - clearly line two is not waiting for line one to finish, > >> but on the > >> other hand, since these are separate processes they don't > >> interfere with each > >> other, which is the first thing I cared about. They finish at different > >> times, and when each finishes apparently depends on how much > >> processing it > >> has to do - not in what order it was started. > >> > >> Problem #2 concerns checking for the presence of a dummy file > >> created at the > >> beginning of the batch and delete at the end. Say you have a > three stage > >> batch, first you create a dummy file, then you start a process > >> such as IMUT > >> which creates an output file, finally, you delete the dummy file. > >> Problem is, > >> as above, step three does not wait for step two. While IMUT may well > >> have > >> _created_ it's output file before the sentinel file is deleted, it may > >> continue to write to that output file for a long time (60 > seconds, on my > >> machine, depending on amount of data). I cannot actually access > >> the output > >> file for further processing until IMUT is finished writing to it, > >> even though > >> my dummy file has long since disappeared. Checking the access > >> properties of > >> the output file would probably work, but that's not the same thing. > >> > >> What my program is doing now, and what works, is creating a batch file > >> as > >> described above to convert each of a group of files using > IMUT. After it > >> launches the batch file it waits a short time (1 second) to make > >> certain the > >> process is running and can be detected. It then enumerate the windows > >> processes looking for IMUT.EXE, while doing > >> Application.ProcessMessges. If > >> IMUT.EXE is not found - some number of times in succession (I > >> finally used > >> 30) - it considers that IMUT has finished and the the next stage of > >> processing may take place. I found that it really was necessary > >> both to wait > >> before looking for process IMUT and also to check for its > non-presence a > >> large number of times in a row. Since Windows takes a 'snapshot' of the > >> running processes which we are starting successively, it's > >> possible to catch > >> it at a point where a given process apparently falls through the > >> cracks. I > >> figure the 1 second wait and the couple of milliseconds of 30 > >> iterations of > >> process checking are acceptable in the circumstanes. > >> > >> Having said all that, I don't know why the routines that use > >> CreateProcess > >> followed by WaitForsingleObject don't seem to work. I'd be > interested in > >> seeing Bo Thomsen's DLL if it includes source, to see what the > >> differences > >> are between that implementation and the ExecAndWait functions > >> I've seen that > >> use CreateProcess and WaitForsingleObject. > >> > >> My program (in Delphi, with source) will be available to whoever is > >> interested, as soon as I've cleaned it up a bit. (And edited it > >> to a version > >> that does not include all the processing following the Tab to Shape > >> conversion, which no one here is likely to care about....) > >> > >> Mickey > >> > >> -- > >> Mickey Feldman > >> > >> [EMAIL PROTECTED] > >> > >> 1) Please reply to List/Newsgroup, not directly unless > >> specifically requested. > >> If it's a useful answer other will be interested too. > >> 2) I'm on digest on all lists - don't take a slow reponse personally. > >> > >> > >> --------------------------------------------------------------------- > >> List hosting provided by Directions Magazine | www.directionsmag.com | > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> Message number: 11337 > >> > > > > > > --------------------------------------------------------------------- > > List hosting provided by Directions Magazine | www.directionsmag.com | > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > Message number: 11359 > > > > > > -- > > Robert Crossley > Agtrix P/L > 9 Short St > PO Box 63 > New Brighton 2483 > Far Southern Queensland > AUSTRALIA > > 153.549004 E 28.517344 S > > P: 02 6680 1309 > F: New Connection > M: 0419 718 642 > E: [EMAIL PROTECTED] > W: www.agtrix.com > W: www.wotzhere.com --------------------------------------------------------------------- List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Message number: 11360
