2

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

3
  • For starting and waiting, you can see here. Killing them off, however, I am not sure in batch.
    – nerdwaller
    Commented Jul 24, 2014 at 13:30
  • How would you terminate the batch ? Ctrl-C ? Commented Jul 24, 2014 at 14:46
  • Do you want that the python scripts run one after the other, or in parallel, and do you need to do anything with their return code ? Commented Jul 24, 2014 at 15:25

1 Answer 1

5

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.