use strict; use warnings; $|++; my $counter = 1; print "($counter) "; while () { chomp; if ($_ eq "error") {print "Error on command #$counter\n";} if ($_ eq "commit") {print "Committing data\n";} if ($_ eq "exit") {print "Exiting program...\n"; exit;} $counter++; print "($counter) "; } #### use strict; use warnings; use Expect; $|++; my $exp = new Expect; $exp->raw_pty(1); $exp->log_file("/tmp/expect.out"); $exp->log_stdout(1); my @commands = ( "This is the first command", "Here is the second command", "error", "commit", "This is the last command", "exit", ); $exp->spawn("./expecttest_server.pl"); foreach my $command (@commands) { print "$command\n"; $exp->send("$command\n"); $exp->expect(1, '-re','\(\d+\)'); } $exp->soft_close();