# Executes a command via a global expect object and # returns the output of the command. # # Arguments: # 1 - Command # Returns: # String variable cotaining the output of the specified command. # sub expect_execute($) { $expect->clear_accum(); my $command = shift; my $x = ''; my $temp = ''; if ( $command =~ /;$/ ) { chop( $command ); } print $expect "$command | sed 's/^/COMMAND_OUT: /g'; echo -n END_; echo EXPECT\n"; $expect->expect( 300, -re => '^END_EXPECT' ); my $result = $expect->exp_before(); ( my @result ) = split( /\n/, $result ); $result = ''; foreach $x ( @result ) { $temp = $x; if ( chop( $temp ) eq "\r" ) { chop( $x ); } if ( $x =~ m/^COMMAND_OUT: / ) { $temp = substr( $x, 13 ); $result = $result . $temp . "\n"; } } return $result; }