Run a .bat file in Windows using Python code?

This has already been answered in detail on SO. Check out this thread, It should answer all your questions:
Executing a subprocess fails

I’ve tried it myself with this code:

batchtest.py

from subprocess import Popen
p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder")
stdout, stderr = p.communicate()

batch.bat

echo Hello World!
pause

I’ve got the batchtest.py example from the aforementioned thread.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)