In the following expect script, you can see that I am trying to match the regex ".*" . That match succeeds, but $expect(0, string) is still not getting set. What am I doing wrong?
First, the script (in a file called /usr/local/bin/py) ...
#!/usr/bin/expect -d
log_user 1
exp_internal 1
match_max 100000
spawn /usr/bin/python3
set prompt "(>>>|\\.\\.\\.) "
set anythingElse ".+"
expect {
-re $prompt {
send_user -- $expect_out(0, string)
expect_user -re "((>>>|\\.\\.\\.) )?(.*)\n"
send -- $expect_out(3, string)
send -- "\n"
exp_continue
}
-re $anythingElse {
set x $expect_out(0, string)
send_user -- $x
exp_continue
}
eof {
exit 0
}
}
And now, here's the output. Note that the failure is on the "set x ..." line:
expect version 5.45
argv[0] = /usr/bin/expect argv[1] = -d argv[2] = /usr/local/bin/py
set argc 0
set argv0 "/usr/local/bin/py"
set argv ""
executing commands from command file /usr/local/bin/py
spawn /usr/bin/python3
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {1277}
Gate keeper glob pattern for '(>>>|\.\.\.) ' is ''. Not usable, disabling the performance booster.
Gate keeper glob pattern for '.+' is ''. Not usable, disabling the performance booster.
expect: does "" (spawn_id exp6) match regular expression "(>>>|\.\.\.) "? (No Gate, RE only) gate=yes re=no
".+"? (No Gate, RE only) gate=yes re=no
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
expect: does "Python 3.4.3 (default, Oct 14 2015, 20:28:29) \r\n[GCC 4.8.4] on linux\r\nType "help", "copyright", "credits" or "license" for more information.\r\n" (spawn_id exp6) match regular expression "(>>>|\.\.\.) "? (No Gate, RE only) gate=yes re=no
".+"? (No Gate, RE only) gate=yes re=yes
expect: set expect_out(0,string) "Python 3.4.3 (default, Oct 14 2015, 20:28:29) \r\n[GCC 4.8.4] on linux\r\nType "help", "copyright", "credits" or "license" for more information.\r\n"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Python 3.4.3 (default, Oct 14 2015, 20:28:29) \r\n[GCC 4.8.4] on linux\r\nType "help", "copyright", "credits" or "license" for more information.\r\n"
can't read "expect_out(0, string)": no such element in array
while executing
"set x $expect_out(0, string)"
invoked from within
"expect {
timeout {
exp_continue
}
-re $prompt {
send_user -- $expect_out(0, string)
send_user -- "!!!\r\n"
expect_user -re "((>>..."
(file "/usr/local/bin/py" line 14)
Thanks in advance.