General discussion
-
CreatorTopic
-
June 15, 2000 at 4:44 am #2074095
Running an exe in VB
Lockedby bcollins · about 21 years, 11 months ago
I am writing a VB program that requires a call to run an exe file. This exe file is producing a txt file that I then need to get some information out of. My problem however is that the VB program makes a call to the program (using Shell() ) and then jumps right into trying to get the information out of the txt file. Is there anyway I can get the VB program to wait until the exe file has finished running?
Topic is locked -
CreatorTopic
All Comments
-
AuthorReplies
-
-
June 15, 2000 at 5:48 am #3776651
Running an exe in VB
by ravikishore_g · about 21 years, 11 months ago
In reply to Running an exe in VB
please use the sendkeys statement and send some character other than control char, immediately after the usage of shell function. while doing so set the wait parameter to true so the control returns to your procedure(next statement ) only after the key is processed. this is a work around for your problem and may not be useful if the program being called takes user input refer to online help
-
September 20, 2000 at 7:04 pm #3755037
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
The question was auto-closed by TechRepublic
-
-
June 15, 2000 at 5:48 am #3776650
Running an exe in VB
by tclere · about 21 years, 11 months ago
In reply to Running an exe in VB
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
LoopIf 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.
-
September 20, 2000 at 7:04 pm #3755038
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
The question was auto-closed by TechRepublic
-
-
June 15, 2000 at 6:03 pm #3776511
Running an exe in VB
by lo · about 21 years, 11 months ago
In reply to Running an exe in VB
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 …
-
September 20, 2000 at 7:04 pm #3755039
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
The question was auto-closed by TechRepublic
-
-
June 15, 2000 at 7:01 pm #3776507
Running an exe in VB
by bogdincescu · about 21 years, 11 months ago
In reply to Running an exe in VB
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.-
September 20, 2000 at 7:04 pm #3755040
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
The question was auto-closed by TechRepublic
-
-
June 16, 2000 at 6:20 pm #3777242
Running an exe in VB
by reassembler · about 21 years, 11 months ago
In reply to Running an exe in VB
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.
-
September 20, 2000 at 7:04 pm #3755041
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
The question was auto-closed by TechRepublic
-
-
June 26, 2000 at 3:57 am #3783914
Running an exe in VB
by ssotton · about 21 years, 11 months ago
In reply to Running an exe in VB
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.
-
September 20, 2000 at 7:04 pm #3755042
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
The question was auto-closed by TechRepublic
-
-
September 20, 2000 at 7:04 pm #3755036
Running an exe in VB
by bcollins · about 21 years, 8 months ago
In reply to Running an exe in VB
This question was auto closed due to inactivity
-
-
AuthorReplies