Reputation: 173
I'm absolutely new to expect command. Suppose that there is a script file named 'a.rb', which is written in ruby:
STDOUT << 'Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh] '
s = STDIN.gets
STDOUT << s
It works as bellow:
$ruby a.rb
Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh] #wait user's input
y # show the user's input and exit
It seems good to use expect command if I want to automate the user's input.
So I tried to make a script file (a.expect):
spawn ruby a.rb
expect "Overwrite /opt/rails/rails_app/Gemfile\? \(enter \"h\" for help\) \[Ynaqdh\] "
sleep 3
send "y\r"
But this script doesn't work and I don't know why. That is my question.
$ expect -f a.expect
spawn ruby a.rb
Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh]
$ # <= expect script has finished because of (maybe) timeout?!
Upvotes: 1
Views: 437
Reputation: 295443
These strings match, but they don't glob to each other. You need to use more escapes.
expect "Overwrite /opt/rails/rails_app/Gemfile\? \(enter \"h\" for help\) \\\[Ynaqdh\\\] "
This is because [abcd]
matches a
, b
, c
or d
-- one character -- not [abcd]
(a six-character string).
Upvotes: 1