I want to use python to run commands in a batch file. The screen capture below shows the batch file and commands in Windows cmd.
I tried to use python to open the batch file.
import os
os.system('C:/Program Files/MetroCon-3.2/RepSend/RepSendQXGA64.bat')
This returns '1' which means failed.
import subprocess
filepath="C:/Program Files/MetroCon-3.2/RepSend/RepSendQXGA64.bat"
p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
stdout, stderr = p.communicate()
print (p.returncode)
This return '0'. And the list of commands are in stdout
and can be shown in python.
The question is how to run the specific command in the batch file as it runs in Windows cmd.
Do you mean something like this?
or this?
If you want to run specific commands from the bat file, you could open the bat file as a txt file (Or use the stdout output), read it line by line and then communicate with the cmd via the winpexpect module.
edit : If I understood you correctly, I could add the read/write buffer implemntation