Home > Back-end >  Windows batch file to open multiple CMDs and execute same python script from all CMDs [closed]
Windows batch file to open multiple CMDs and execute same python script from all CMDs [closed]

Time:09-16

I have a python script which I want to run from the Windows CMD.

However, I need to open 30 such CMDs and run this same python file from all these CMDs. (Hence, going with a batch file)

Basically, I want to achieve teh foll:

  1. Create a batch file
  2. Open a cmd and run this file
  3. This script should open 30 other CMDs.
  4. Each and every CMD should execute this same python script.

How do I achieve this?

CodePudding user response:

You could get the effect that you want by creating a relatively simple script: I haven't tested it on a windows machine, so I would test it and debug, but this will give you the broad strokes:

The paths below are relative, so this script will need to be in the same directory as your server and your client.

py %%~dp0\server.py
for /l %x in (1, 1, 30) do{
  py %%~dp0\client.py
}

CodePudding user response:

The following seems to satisfy my requirement:

for /l %%x in (1, 1, 30) do (
       start cmd /c "python <script_name>.py"
)
  • Related