1
我試圖使用Expect與長時間運行的交互式進程交談。我正在使用cat -un來模擬這個過程。我的代碼如下:使用Perl與程序進行通信期望
#!/usr/bin/perl
use strict;
use warnings;
use Expect;
my $timeout = 4000;
my $exp = Expect->spawn("cat -un");
my $text = <STDIN>;
$exp->send($text);
$text = <STDIN>;
$exp->send($text);
$exp->expect(undef); # Forever until EOF
$exp->expect($timeout); # For a few seconds
$exp->expect(0);
$text = <STDIN>;
$exp->send($text);
$exp->expect(undef); # Forever until EOF
$exp->expect($timeout); # For a few seconds
$exp->expect(0);
我按第一個字符串+輸入並得到沒有輸出(顯然)。我輸入第二個字符串並按下cat -un轉儲到屏幕上的enter和stdout。我的第三個字符串不會產生任何輸出,但我希望它將stdout轉儲到屏幕上。
我的目標是與在屏幕上放置文本(要求用戶從菜單中進行選擇)的交互式過程進行交流,然後讓用戶輸入響應並將其發送到流程(這會生成更多輸出和更多菜單)。
期待似乎是最簡單的方法來做到這一點。請幫我。