summaryrefslogtreecommitdiff
path: root/example/passwdprompt
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-11-04 17:21:04 -0800
committerAnas Nashif <anas.nashif@intel.com>2012-11-04 17:21:04 -0800
commite0b431a48cc3ac5d3ec32f06eddd9708ad655fa2 (patch)
treece4c73521220fbb751c2be6a42e85ff6a6cbff97 /example/passwdprompt
downloadexpect-e0b431a48cc3ac5d3ec32f06eddd9708ad655fa2.tar.gz
expect-e0b431a48cc3ac5d3ec32f06eddd9708ad655fa2.tar.bz2
expect-e0b431a48cc3ac5d3ec32f06eddd9708ad655fa2.zip
Imported Upstream version 5.45upstream/5.45
Diffstat (limited to 'example/passwdprompt')
-rwxr-xr-xexample/passwdprompt35
1 files changed, 35 insertions, 0 deletions
diff --git a/example/passwdprompt b/example/passwdprompt
new file mode 100755
index 0000000..163e493
--- /dev/null
+++ b/example/passwdprompt
@@ -0,0 +1,35 @@
+#!/depot/path/expect
+
+# This script prompts for a passwd from stdin while echoing *'s
+
+# Prompt MUST be passed as argument to avoid falling into the classic
+# prompt-before-echo-has-been-disabled mistake.
+
+proc getpass {prompt} {
+ set sttyOld [stty -echo raw]
+ send_user $prompt
+
+ set timeout -1
+ set passwd ""
+
+ expect {
+ -re "\r" {
+ send_user \r\n
+ } -re "\010|\177" {
+ if {[string length $passwd] > 0} {
+ # not all ttys support destructive spaces
+ send "\010 \010"
+ regexp (.*). $passwd x passwd
+ }
+ exp_continue
+ } -re . {
+ send_user *
+ append passwd $expect_out(0,string)
+ exp_continue
+ }
+ }
+ eval stty $sttyOld
+ return $passwd
+}
+
+puts "The password you entered was: [getpass "Password: "]"