Need help in calling .bat
file via python in windows server.
Currently the .bat
file is used to encrypt the password and generate password file .
when the admin run this .bat
file, they ll execute below command
runbatch.bat filename
On executing the above it prompt us to enter password
....Enter the password to encrypt
On entering the password it generate the password file in the specified folder.
Now the requirement is to call this .bat
file via python.
Reason behind this to create an API and give option to user to generate the password file from their end. When user tries to generate the password file it prompts for password and password file name and passes those parameters to python script which in return calls a .bat
file
I am not sure how to echo password input as we do directly in cmd
.
Echo password| runbatch.bat filename
In python I have defined .bat
location on os.dir
and using popen
subprocess option to run the
.bat` but not sure how to pass password to the command.
import sys
import os
import subprocess
sPassword = $Password
sPasswordFile = $PasswordFile
sInstance = "D:/API/bin" os.chdir(sInstance)
ScriptName = sInstance + "/encryptpassword.bat"
command = '%s "%s"' % (ScriptName, sPasswordFile)
p = subprocess.Popen(command) retcode = p.wait()
Any help will be highly appreciated.