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

154 Views Asked by At

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.

1

There are 1 best solutions below

1
deba prasad nayak On BEST ANSWER

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)