From: Eric Bollengier Date: Sun, 24 Oct 2010 17:22:32 +0000 (+0200) Subject: bweb: add send_one_cmd that uses Open2 instead of Expect X-Git-Tag: Release-5.2.1~966 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=88d6d63ee9a0d134cccc06b16d4b2e9d2d74cc9c;p=bacula%2Fbacula bweb: add send_one_cmd that uses Open2 instead of Expect --- 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) = @_;