能否不使用interact函数完全模拟expect的interact功能?
不使用
interact重写Expect转发脚本 本问题部分出于好奇,部分是我此前问题的子问题。
请问能否在expect中不使用interact函数重写以下脚本?
eval spawn $argv interact
我已进行三次尝试,但均出现输出重复问题,推测是每次send操作触发了另一端的expect,但尚未确定如何避免该问题。
需说明的是,我刻意选择使用tty而非user_spawn_id,因为希望捕获并转发用户输入内容以及tty的响应内容至目标进程。
尝试1
#!/usr/bin/expect eval spawn $argv stty raw expect_background "?" { send_tty -- [set expect_out(0,string)] } expect_tty "?" { send -- [set expect_out(0,string)] exp_continue } stty cooked
尝试2
#!/usr/bin/expect eval spawn $argv stty raw expect { -i $spawn_id "?" { send_tty -- [set expect_out(0,string)] exp_continue } -i $tty_spawn_id "?" { send -- [set expect_out(0,string)] exp_continue } } stty cooked
更新:即便使用user_spawn_id仍会出现输出重复,推测存在其他问题:
尝试3
#!/usr/bin/expect eval spawn $argv stty raw expect { -i $spawn_id "?" { send_user -- [set expect_out(0,string)] exp_continue } -i $user_spawn_id "?" { send -- [set expect_out(0,string)] exp_continue } } stty cooked
内容的提问来源于stack exchange,提问作者merlin2011
相关产品推荐
相关产品推荐

