in reply to How can I show all input and output with Expect.pm
I see two main problems.
First, the following lines are in the wrong order for what you want your output to be:
print "$command\n"; $exp->send("$command\n"); $exp->expect(1, '-re','\(\d+\)');
You probably want this order instead:
$exp->send("$command\n"); print "$command\n"; $exp->expect(1, '-re','\(\d+\)');
Second, this:
my $counter = 1; print "($counter) ";
Should just be this:
my $counter = 0;
The extra stuff is just junk since you print and increment the counter in your loop. This change will fix printing 1 and 2 together like you observed here: (1) (2) Here is the second command
EDIT: Hmmm. Looking at your scripts more closely, I'm having second thoughts about this. What if you just print it all from the server script? Like this:
while (<STDIN>) { chomp; $counter++; print "($counter) $_\n"; if ($_ eq "error") {print "Error on command #$counter\n";} if ($_ eq "commit") {print "Committing data\n";} if ($_ eq "exit") {print "Exiting program...\n"; exit;} }
In Section
Seekers of Perl Wisdom