pythonshellunixexpectpython-keyring

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


I want to get the pw value from python, something like

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)

let me know if there is any other way to do this.


Solution

  • I just missed one thing:

    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)