python - 如何从expect捕获shell变量中的python输出?
问题描述
我想从 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)
推荐阅读
- javascript - 无法使用 fetch 获取资源,NetworkError
- c# - INotifyPropertyChanged 已实现,但文本块仅更新一次
- google-chrome - 无头 Chrome 会自动更新吗?
- javascript - 如何通过在指定范围内引入点来减少字符串
- python - 显示空数据框的代码
- angular - Angular 6 - 无法使用 ngModel
- arrays - 如何在VBA中的数组中保留某种形式的数字
- java - 正则表达式从 json 获取键和值
- javascript - 如何在多选 jquery 插件中获取未经检查的值
- java - Java:将多个表中的 SQL 选择映射到多个实体中