From 88d6d63ee9a0d134cccc06b16d4b2e9d2d74cc9c Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sun, 24 Oct 2010 19:22:32 +0200 Subject: [PATCH] bweb: add send_one_cmd that uses Open2 instead of Expect --- gui/bweb/lib/Bconsole.pm | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gui/bweb/lib/Bconsole.pm b/gui/bweb/lib/Bconsole.pm index 6c218d1f4c..52fb40de64 100644 --- a/gui/bweb/lib/Bconsole.pm +++ b/gui/bweb/lib/Bconsole.pm @@ -42,7 +42,7 @@ use strict; package Bconsole; use Expect; use POSIX qw/_exit/; - +use IPC::Open2; # my $pref = new Pref(config_file => 'brestore.conf'); # my $bconsole = new Bconsole(pref => $pref); sub new @@ -176,7 +176,7 @@ sub connect # TODO : we must verify that expect return the good value - $self->expect_it('*'); +# $self->expect_it('*'); $self->send_cmd('gui on'); } return 1 ; @@ -195,6 +195,32 @@ sub before return $self->{bconsole}->before(); } +# use open2 to send a command, skip expect, faster +sub send_one_cmd +{ + my ($self, $line) = @_; + my $ret=''; + my $cmd = $self->{pref}->{bconsole} ; + if ($self->{dir}) { + $cmd = $cmd . " -D '$self->{dir}'"; + } + my ($OUT, $IN); + my $pid = open2($OUT, $IN, $cmd); + print $IN "$line\n"; + close($IN); + my $l = <$OUT>; # Connecting to + $l = <$OUT>; # 1000: OK + $l = <$OUT>; # Enter a period + $l = <$OUT>; # line + + while ($l = <$OUT>) { + $ret .= $l; + } + close($OUT); + waitpid($pid, 0); + return $ret; +} + sub send_cmd { my ($self, $cmd) = @_; -- 2.39.5