Sorry about the last bit of code if you tried it and it didn't work (I just tried it now). The buffer needs to be cleared out . The code is now commented to explain what each part does. Is this what you wanted or am I completely off the wall?:
#!/usr/bin/perl
use strict;
use Expect;
my $session = new Expect;
$session->spawn("/usr/bin/bash");
# clear buffer
$session->expect(20, -re, ".");
$session->clear_accum();
# cd to required dir
print $session "cd \/home\/homedir\r";
$session->expect(90, -re, "bash");
# wait
sleep 20;
# get the results of the command and assign them to an array
print $session "ls \-altr\r";
my @array = $session->expect(60, -re, "bash");
$session->clear_accum;
my @array1 = split('\n', $array[3]);
# print out each element of the array so that they can be further proc
+essed
for (my $i = 0; $i <= $#array1; $i++) {
print "\nElement $i is\n$array1[$i]\n";
}
|