繁体   English   中英

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

[英]how to capture the python output in a shell variable from expect?

我想从 python 中获取 pw 值,比如

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

文件.py

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

如果有其他方法可以做到这一点,请告诉我。

我只是错过了一件事:

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) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM