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

How send EOF to process in Expect script?

1,314 views
Skip to first unread message

Oleksandr Gavenko (aka gavenkoa)

unread,
Sep 12, 2011, 1:53:34 AM9/12/11
to
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.

How get final output from external process?

Bezoar

unread,
Sep 13, 2011, 11:54:40 PM9/13/11
to
On Sep 12, 12:53 am, "Oleksandr Gavenko (aka gavenkoa)"
End sends with \r not \n
Likely need to enter event loop for background expect to respond to
events.
e.g. vwait forever
Where
forever is a variable.
To get cat to exit send cntrl-d which ibelieve is /04> How get final
output from external process?

Oleksandr Gavenko (aka gavenkoa)

unread,
Sep 15, 2011, 6:36:30 PM9/15/11
to
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]
0 new messages