13 replies
by bcollins
by tclere
sTxtFile = "C:\path & filename.txt)
sExeFile = "C:\path & application.ext)
'Remove old copy of txt file
If Dir(sTxtFile)<>"" then Kill (sTxtFile)
'Run the exe file
Call Shell(sExeFile, vbNormalFocus)
'Wait until file is written to continue
Do While Dir(sTxtFile) = ""
DoEvents
Loop
If the txt file is long, the Dir(sTxtFile) command may see the file before it is completed. You could add a few seconds of a delay if this occurs. If you have access to rewrite the exe being called, you could also write a tmp file before the Shell() command and remove the tmp file as the last step in the sExeFile. I have a routine (somewhat long) that will check if the sExeFile is running in Task Manager. Let me know if you want me to send you this code.
by bcollins
by lo
Another workaround - Try to open the text file in exclusive I/O mode. You should get an error return until it is close by the other program. In conjunction with Dirs to make sure it is there to start, wait and a loop, that should work.
Yet one more - if you have access to the Run program, add a 'last line'. If the file isn't too large, open, read discard until you the the 'last line' record.
BTW - neither of these are very efficient in system usage, but ...
by bcollins
by bogdincescu
I believe that if you could make a slight change to the .exe that generates your text file so that, after generating the needed text file it would write a little something to a file, say done.log, then, your VB program could loop until it finds the file done.log, then start reading the text file.
If you can't change the .exe file (say, because you can't obtain the sources), you may use a batch like the following:
-------
@echo off
del done.log
prepare_stuff.exe
echo done>done.log
------
So, your VB program would call the .bat and start using the generated text file only after it finds the done.log file. Yet, it certainly would be the best to have the done.log generated through your .exe file, for, if something goes wrong with your .exe and it dies for some reason, then your VB program won't use incomplete data.
by bcollins
by reassembler
The Windows API has functions that exist for the sole purpose of starting programs and waiting for programs to finish.
You get a handle to the process you want to wait on by call CreateProcess.
Use the handle in call to WaitForSingleObject.When WaitFOrSingleObject returns, the process is dead.
by bcollins
by ssotton
I'd like to say I thought of this one myself, but I got it directly from Microsoft.
The answer is in their knowledge base at:
http://support.microsoft.com/support/kb/articles/Q129/7/96.asp?LN=EN-US&SD=gn&FR=0
The functions the article gives you allow you to execute a program and then wait till its finished before you continue with program execution. Copy the code into a .BAS module and save it, you'll find its very useful.
by bcollins
by bcollins
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending