Reputation: 345
How do I write a batch script in windows that starts 2 python scripts and waits for both of them to return? and also terminates both of them if I terminate the batch script?
Already asked this and got no answers...Also looked for solutions here, but the ones listed do not wait for a return from execution of the python scripts.
EDIT: yes terminate it using ctrl+C
Upvotes: 2
Views: 8484
Reputation: 413
To make sure that the other scripts wait for your proccess to be complete, call it using start /wait
- this calls another batch or command line script:
start /wait batchforpython.bat
sobatchforpython.bat
would contain
C:\Python34\python.exe C:\Where\your\python\file\is.py
which is how you can call your python program from a batch script.
Finally, in Python, you can use this to check if a program is running (for you, that would be cmd
or command.com
) and if it is not there then the batch script has been terminated, so you can use sys.exit()
to exit Python.
Upvotes: 5