Iam会产生一个提示输入密码的进程,如何提供密码? 我在stackoverflow中找到了以下解决方案,但似乎无法正常工作它是否提示输入密码
class Actions():
def console(self):
return subprocess.Popen("myprogram",
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
close_fds=True)
def ask_password(self, passw):
delete = self.console().communicate("%s" % (passw))
return(delete)
def main():
password_string = "abc123"
print Actions().password(password_string)
打印
('','密码:')
--bash ---
>./myprogram
Password:abc123
"Welcome to console"