Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expect can't send ctrl-z control character

1,274 views
Skip to first unread message

jef peeraer

unread,
Oct 13, 2011, 7:27:18 AM10/13/11
to
i have a sms-gateway (AS551) which i want to communicate with. it has a
telnet interface, which is fine. i am a an old times tcl-user, so i
remembered expect, the ideal tool to automate these telnet sessions. i
wrote a little script, and it works until the sending of the text
message (the final goal!). i can test everything with a plain telnet
session, after i modified the tty so i can issue a ctrl-z, followed by a
ctrl-d.
in the expect script, the sending of these control characters don't seem
to work, and the control-z character doesn't show up in a wireshark
session. The script is below. Thanks for any hints!

#!/usr/bin/expect --
#

if {[llength $argv] == 0} {
puts "usage : send_sms number message"
exit 1
}
#stty raw -echo
set CTRLZ \x1A
set CTRLD \x04
set telnet_host localhost
set telnet_port 23
set number_to_sms [lindex $argv 0]
set message_to_sms [lindex $argv 1]
puts "number_to_sms $number_to_sms\r"
puts "message_to_sms $message_to_sms\r"
set timeout 60
log_user 1
exp_internal 1
set spawn_id [spawn telnet $telnet_host $telnet_port]
expect "'^]'."
#this sets text mode"
send "at+cmgf=1\r"
expect "OK"
#this sets the destination number
send "at+cmgs=\"$number_to_sms\"\r"
expect "> "
#type the message and end with CTRL-Z (doesn't seem to work,send CTRL_Z
later)
exp_send "$message_to_sms\r"
expect -re "(\[^\r\n]*)\r\n"
#remove susp control code from tty ( otherwise CTRL-Z will suspend the
program)
stty susp ^-
set res [stty -a]
puts $res
#send CTRL-Z followed by CTRL-D to flush the buffer
exp_send "\x1A\x04"
expect "OK"
exit 0

Derek

unread,
Oct 18, 2011, 4:35:48 PM10/18/11
to
You could use exp_internal 1 to make sure its sending what you think
its sending

Dec

jef peeraer

unread,
Oct 19, 2011, 3:44:54 AM10/19/11
to
it's in the script, i even tested it with a simple netcat listener at
the other side. ctrlz gets eaten somewhere.....

jef
>
> Dec

0 new messages