November 26th, 2012, 04:29 AM
How to pass `echo t | ` as arg in `subprocess.check_output`
I have called an exe using subprocess.check_output from my python script.
when the script is executed, it would ask user to enter an input key,
res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT)
In Command prompt, i am able to pass the input key to the process while calling itself with below command and i am able to get the output:
(R)eject, accept (t)emporarily or accept (p)ermanently?
from python to call the exe, i am not able to pass the "echo t | " in subprocess.check_output function.
echo t | svn.exe list Https://127.0.0.1:443/svn/Repos
Is there any way to do this.
November 26th, 2012, 10:18 AM
subprocess.check_output("echo t | cat", shell=True,stderr=subprocess.STDOUT)
[/code] are essential for python code and Makefiles!
November 28th, 2012, 06:36 AM
Originally Posted by b49P23TIvg
Thanks for your input. but that doesnt work for me.
I resolved the issue by using two subprocesses, and providing the output of the first process as input to second process.
p = subprocess.Popen("echo t |", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p1 = subprocess.Popen(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], shell=True, stdin=p.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
output = p1