python3 subprocess run sudo cmd in remote failed

lampahome pahome.chen at mirlab.org
Tue Sep 17 00:13:57 EDT 2019


Hello, I use python3.5 and found no way to solve this problem

>from subprocess import Popen, PIPE
>ps = Popen('ssh -o \'StrictHostKeyChecking no\' hello at 192.168.80.11 \'sudo
sysctl -w vm.drop_caches=3\', stdin=PIPE, stdout=PIPE, stderr=PIPE,
bufsize=0, shell=True)
>  hello at 192.168.80.11's password:

what I tried many times like enter password, but it failed.
I just want to use ps.stdin.write(password) to send password, but it always
jump password prompt immediately.

How to solve this



More information about the Python-list mailing list