This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
программирование_диалогов_expect [2026/08/19 14:01] val |
программирование_диалогов_expect [2026/10/28 15:01] (current) val [Communigate CLI] |
||
|---|---|---|---|
| Line 67: | Line 67: | ||
| #!/usr/bin/expect | #!/usr/bin/expect | ||
| - | set cmd [lindex $argv 0]; | + | set timeout 10 |
| - | spawn telnet localhost 106 | + | if {[llength $argv] < 1} { |
| - | + | send_user "Использование: $argv0 \"КОМАНДА\"\n" | |
| - | expect "200" { | + | exit 1 |
| - | send "USER postmaster\n" | + | |
| } | } | ||
| - | expect "300" { | + | set cmd [lindex $argv 0] |
| - | send "PASS Pa\$\$w0rd\n" | + | |
| - | } | + | |
| - | expect "200" { | + | send_user "Введите пароль для postmaster: " |
| - | send "$cmd\n" | + | stty -echo |
| - | } | + | expect_user -re "(.*)\n" |
| + | set pass $expect_out(1,string) | ||
| + | stty echo | ||
| + | send_user "\n" | ||
| - | expect "200" {} | + | spawn telnet localhost 106 |
| - | sleep 1 | + | expect "200" { send "USER postmaster\n" } |
| - | send "QUIT\n" | + | expect "300" { send "PASS $pass\n" } |
| - | send_user "\n" | + | expect "200" { send "$cmd\n" } |
| - | exit 0 | + | |
| - | </code><code> | + | |
| - | mail# chmod +x cgp_cli.exp | + | |
| - | mail# ./cgp_cli.exp 'CREATEACCOUNT user2 {Password = "password2";RealName = "Петр Петрович Петров";}' | + | expect "200 data follow" { |
| + | expect { | ||
| + | timeout {} | ||
| + | eof {} | ||
| + | -re ".*\n" { exp_continue } | ||
| + | } | ||
| + | } | ||
| - | mail# ./cgp_cli.exp 'GETACCOUNTSETTINGS user2' | + | send "QUIT\n" |
| + | expect "200" | ||
| </code> | </code> | ||