I just observed that when you execute a batch file in Windows XP, it is executed synchronously. All the programs are executed one-by-one with subsequent programs waiting for the previous ones to finish. So the behaviour you mentioned was not observed in Windows XP.
Windows 98 behaved differently. All GUI programs were started in a quick scan without waiting for the previous ones to finish and the batch file was also finished before these programs.
To handle this problem, you need to execute your programs using the START command. This command is used to start other programs and offers a /WAIT option which allows you to execute the command synchronously as you require. Fortunately START is supported by Windows XP and Windows 98 so you don't need to write different batch files for different platforms.
As a test, I just wrote a sample batch files with the following two lines.
[tt]
calc.exe
notepad.exe [/tt]
On Windows XP, it started the Calculator. After closing the Calculator it started Notepad. After having done with the Notepad the batch file finished.
On Windows 98, both Calculator and Notepad started one after the other and the batch file finished immediately without any delay.
To make it work synchronously on Win98, I modified my batch file as under.
[tt]
start/wait calc.exe
start/wait notepad.exe [/tt]
And this fixed it. Both on WinXP and Win98.
To learn more about START, type [tt]START/?[/tt] at the command prompt.
Unfortunately the application started makes the batch file exit after it starts and prior to its ending. I rewrote the original batch file to use the start/wait option you suggested but it had no effect on the way the batch file behaved
Can you show us the contents of your batch file? And some details about what you are doing in the batch file and what do individual commands do? This may help us to simulate and reproduce the problem. Also tell us about your operating system.
I tried the above method and found it working with no problems.
Also tell what is the behaviour of the batch file if you execute it (a) from Windows and (b) from Command Prompt instead of VB's Shell function.
This information may help us to narrow down the problem.
the program is running under XP
if I run it from a command prompt it behaves in just the same way the batch file closes before the program has finished processing
i have stripped the batch file down to just run the command just the command it behaves exactly same way the batch file as is now looks like this
------------------------------------------
rem echo off
%ptc_drive%\CADapp\pro25_m090\bin\proe.exe
------------------------------------------
I have looked in the task manager as the program is executing first there is a process called proe.exe this soon disappears and is replaced with another process called xtop.exe
I assume the batch file thinks that the program has finished as soon as the proe.exe process ends
Your assumption seems to be true. The batch file only monitors the proe.exe process and not the xtop.exe process. Thats why it finishes before you expect.
What you should do now is to monitor the xtop.exe process externally. This can be done quite easily. You need to obtain the process identifier of xtop.exe after it is running. Use the process identifier to monitor the process using the OpenProcess / WaitForSingleObject / CloseHandle trio in the same way it is demonstrated in my first post in thread222-859655. The process identifier of a running process can be obtained using the GetProcessId function I posted in thread222-837273.
So here is a pseudo-code of the whole program.
+ Start your batch file using ShellWait.
+ When the batch file is finished, it means that proe.exe is finished and xtop.exe is running.
+ Obtain process identifier of xtop.exe using the GetProcessId function. (thread222-837273)
+ Track xtop.exe using OpenProcess/WaitForSingleObject/CloseHandle. (thread222-859655)
+ When xtop.exe has finished, your batch file is practically finished.
Note that, as you are running Windows XP, you don't need "START/WAIT" option.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.