]> git.sur5r.net Git - bacula/bacula/commitdiff
bweb: add send_one_cmd that uses Open2 instead of Expect
authorEric Bollengier <eric@eb.homelinux.org>
Sun, 24 Oct 2010 17:22:32 +0000 (19:22 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Fri, 12 Nov 2010 08:13:57 +0000 (09:13 +0100)
gui/bweb/lib/Bconsole.pm

index 6c218d1f4c226f783f05b5de6c28c03bcd6e02d7..52fb40de6497c15a2df67d3010c4f43c7f1fd8be 100644 (file)
@@ -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) = @_;