Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gets not waiting for user input in expect script

When i try to run the following expect script, it just finishes running instead waiting for user input. Could someone tell me what i am doing wrong?

#!/usr/bin/expect
puts -nonewline stdout "Enter device id:"
flush stdout
gets stdin id
puts -nonewline  stdout "Enter device name:"
flush stdout
gets stdin name
like image 224
woodstok Avatar asked Apr 30 '12 15:04

woodstok


1 Answers

Expect alters the Tcl gets command so that it doesn't wait for standard input; to read a line while waiting for it, you need to do this instead of gets stdin id:

# Read input to stdin
expect_user -re "(.*)\n"
set id $expect_out(1,string)
like image 87
Donal Fellows Avatar answered Nov 07 '22 15:11

Donal Fellows