On 14 сен, 06:54, Bezoar <
cwjo...@gmail.com> wrote:
> On Sep 12, 12:53 am, "Oleksandr Gavenko (aka gavenkoa)"
> > I want finish interaction with external process in Expect script.
>
> > Look to example:
>
> > spawn cat
> > expect_background -re ".+" {
> > send_user $expect_out(0,string)}
>
> > exp_send "Hello World\n"
> > sleep 1 ;# XXXXX
>
> > Without 'sleep' command I don't get response from 'cat' utility as (I
> > think) expect script
> > finish working.
>
> > With 'close' command before 'sleep' I also does not get message form
> > 'cat' as (I think)
> > 'cat' process destroyed and Expact don't wait for it output.
>
> > I try modify script to
>
> > spawn cat
> > expect_background -re ".+" {
> > send_user $expect_out(0,string)} eof {
>
> > send_user $expect_out(0,string)}
>
> > exp_send "Hello World\n"
> > close
> > sleep 1
>
> > but it also don't work.
>
> End sends with \r not \n
OK, I already learn this...
> Likely need to enter event loop for background expect to respond to
> events.
> e.g. vwait forever
> Where
> forever is a variable.
Please write more clear. I don't understand...
> To get cat to exit send cntrl-d which ibelieve is /04
Good point. I already learn this tecniques... Look to my example:
stty raw
expect {
-i $mult3_id -re "(\[0-9]+)\r" {
puts "xxx $expect_out(1,string) xxx"
if { [expr $expect_out(1,string) != 4] } {
send -i $div2_id "$expect_out(1,string)\r"
exp_continue
}
}
-i $div2_id -re "(\[0-9]+)\r" {
puts "yyy $expect_out(1,string) yyy"
send -i $mult3_id "$expect_out(1,string)\r"
exp_continue
}
-i $user_spawn_id \x0c { }
}
stty -raw
send -i $div2_id \x04
send -i $mult3_id \x04
wait
But is I set
set stty_init "raw"
I can not do
send -i $div2_id \x04
any more, so I need
exec kill [exp_pid -i $div2_id]