我有以下代码,行"调用(" ectool --server = commander.company.com登录用户名",shell = True)"提示输入密码,我该如何通过 密码到shell?
from subprocess import call
def main():
list = ['741679','741477']
call("export COMMANDER_SERVER=commander.company.com" ,shell=True)
call("ectool --server=commander.company.com login username",shell=True)
#need to pass password
if __name__ == '__main__':
main()
答案 0 :(得分:0)
您可能想要查看expect库以获取python。该库允许您编写“脚本”,该脚本根据提示指定程序应如何响应子进程。
你应该可以这样做:
import pexpect
child = pexpect.spawn ('ectool --server=commander.company.com login username')
child.expect('Password:')
child.sendline('<supersecretpassword>')
注意:信用到期 - https://stackoverflow.com/questions/2387731/use-subprocess-to-send-a-password