28

Here's part of an expect script

#/usr/bin/expect 

spawn -noecho kwalletcli -f Passwords -e keyofmypassword
expect ".*"
set passwd $expect_out(buffer)

# do some thing
# ...

It read password from kwalletcli, and store in variable passwd. So I can connect to the servers with this passwd.

However, the output of kwalletcli is pass through expect and show on console. How can I hide that.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
yegong
  • 739
  • 1
  • 7
  • 15
  • Does this help? http://stackoverflow.com/questions/681928/how-can-i-make-an-expect-script-prompt-for-a-password BTW this 夜弓 not that *叶公* :) – Kent Jan 30 '13 at 13:24

3 Answers3

62

Try adding

log_user 0

to your script. That should turn off the display to stdout.

If you want to turn it on again for the "do some thing" part of the program, re-enable it

log_user 1
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1

using this command:

exec >log 2>&1

you can forward your output to a file or you can pass it to dev/null

Hamid Reza Moradi
  • 429
  • 2
  • 4
  • 11
0

is with -stty and stty

stty -echo send_user "Password: " expect_user -re "(.*)\n" set password $expect_out(1,string) stty echo

  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 02 '21 at 19:25