I want to interactive with subprocess terminal and send password, but I noticed that I could not get any stdout
if some program call getpass(prompt)
(http://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/getpass.html)
That means I could not interactive with sudo
and ssh
, so how to solve this problem? Thanks.
Here is the example:
process = subprocess.Popen(['sudo', 'apt', 'update'],
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
while True:
# prefix '>>' in parent process
# but we could see the stdout without prefix, that means read() never return
# the subprocess just ignored the redirect of stdout
print('>>', process.stdout.read())
time.sleep(1)