Batch File to access multiple directories and run python script in different command prompts

Asked

Viewed 619 times

0

Hello everybody all right? I’m trying to create a bat file to run python scripts in different directories, something like that:

 C:\Test
    | --- Test1\example.py
    | --- Test2\example.py
    | --- Test3\example.py
 | --run.bat

I have several folders within Test, 'Test1', 'Test2' and 'Test3', I need to run them simultaneously with different command prompts, I got something like this:

@echo off
set back=%cd%
for /d %%i in (C:\Test\*) do (
start
cd "%%i"
python example.py
pause
cd %back%
)

But it runs only one script and goes back to the initial directory, so I noticed, I believe it is running for only in the first directory, some hint for this problem?

Thank you!

1 answer

0


managed to solve this problem, follows the code of . bat created:

@echo off
echo "this is the main batch script"
for /d %%i in (C:\Test\*) do (
start python "%%i\example.py"
)
pause

Browser other questions tagged

You are not signed in. Login or sign up in order to post.