Link to home
Start Free TrialLog in
Avatar of Annette Wilson, MSIS
Annette Wilson, MSISFlag for United States of America

asked on

Batch File Run Exe in cmd - wait til complete and exit

Hi!

How do I create a batch file that runs through cmd, waits until a process is complete and closes?
Avatar of chaau
chaau
Flag of Australia image

Just use command "call", like this:
call notepad.exe
call calc.exe

Open in new window

Save this as a file with an extension of bat. Run it. You will see that notepad opens first. The batch file will wait until you close the notepad. Then calculator will popup. The batch file will remain open until you close the calculator
Avatar of englanddg
englanddg

@chaau has it!
Often that does not work, because CALL does not wait for the process to finish.
start /w "" notepad
forces the wait.
Avatar of Annette Wilson, MSIS

ASKER

ok,

So, I'm using:

Start  /WAIT C:\Srcripts\myscript.exe  

But the script starts another process.  I want to close everything when the other process is complete.
What is not closing when the other process finishes? Can you show us the screenshot
I don't have a screen shot to show at this time because running the script may interrupt production.

Myscript.exe is an autoIT script that opens windows, sets up certain values, runs an executable file and sends an email.  

Is there a way to have the batch file wait for a specific process to complete then close everything when it is complete?
the START /w command will wait for Myscript.exe. However, if Myscript.exe does not wait for other processes and exits after initiating them then you need to adjust the AutoIT script to wait.
There are means to wait for a specific process to finish, if nothing else eorks:
:wait
tasklist /im notepad.exe >nul && goto wait

Open in new window

@chaau,

It's been a real challenge trying to get my autoIT script to wait.  It doesn't even wait until windows close before it send the email which should only send after the line items are complete.

I have the scripts set up on each of the servers.  Will let you know what works.
Why don't you then just move all the script to a batch file and run it from there. What is the advantage to use the autoIT script?
I'm using AutoIT because it does open the windows and run the program as and has the email feature.  Don't know that a batch file can do all of this.
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks chaau.  It looks like I will have to get this done quickly using VBScripting.  This particular solution is not working for me.  I will post another question for help on VB Scripting.