I want to call an exe-file and already input parameters/input-data.
cmd = dir_path + 'file.exe do something test'
p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
This is already working fine. If you do that by using the exe-file you would press enter to execute the next step which would be entering your username. Then password and so on. Now I dont know how to implement this into my script, that this steps are all done my the script. Basically i dont know how to do the ENTER step with python. Thx for any help.
UPDATE
Tried now 2 ways (all mentioned within this question or others on stackoverflow).
way 1>
p = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, universal_newlines=True)
# cmd represents the path of the exe file
p.stdin.write(username+"\n")
p.stdin.write(password+"\n")
p.sdin.close()
way 2
p = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, universal_newlines=True)
out,err = p.communicate("\n".join([username,password,"\n"]))
# last \n should terminate the exe file and communicate should wait for the process to exit
Both ways present me with the same output in one line:
Username: Password:
normally i hoped it would be:
Username: "username wrote by process + \n"
Password: "password wrote by process + \n"
the application is running on windows7 (has to be) and the exe file runs within command line.
So is it maybe possible that the exe does not support way1 and way2 so its not possible to write it through a subprocesss or am I making a major mistake?!
thanks again for any help.