I try to run a
.bat file in Windows using Python script.
I write Python code :
import os os.system("D:\xxx1\xxx2XMLnew\otr.bat ")
Output: when try to run the file its just give a blink of the command prompt, and the work is not performing.
Note: I try with alternate slash also , but it is not working.
And I also want to save output of the file in another file.
Can anyone suggest how can I make the script runnable.
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:
from subprocess import Popen p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder") stdout, stderr = p.communicate()
echo Hello World! pause
I've got the batchtest.py example from the aforementioned thread.