如何从expect捕获shell变量中的python输出?

2024-03-28 15:54:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从python中获取pw值,类似于

spawn python3 $pscript
expect "password:"
send "$enc_password\r"
set outcome $expect_out(buffer) --getting empty array in outcome

file.py

import keyring
pw = keyring.get_password("system","user")
print(pw)

如果还有其他方法,请告诉我


1条回答
网友
1楼 · 发布于 2024-03-28 15:54:34

我只是错过了一件事:

spawn python3 $pscript
expect "password:"
send "$enc_password\r"
expect "blah"  this extra expect, else the outcome will be an empty array
set outcome $expect_out(buffer) 

相关问题 更多 >