1

I'm trying to use Expect.pm on an old machine with perl 5.8.8. It works but when I send a text that contains a "#" sign it is removed from the text. Is there a way to escape/protect it?

Thanks

Sorry corrected it is 5.8.8

#!/usr/bin/perl
use Expect;
use IPC::Open2;
my $cmd="./rec";
my $e = Expect->new;
$e->debug(0);
$e->spawn($cmd) or die;
$e->log_stdout(1);
$e->raw_pty(0);
my $cmd="#some command";
print "cmd: [$cmd]\n";
$e->send($cmd);
$e->expect(1,
  [ qr/^I:.*/ => sub { my $exp = shift; print "ok\n"; exp_continue;}],
  [ qr/^E:.*/ => sub {
        my $self = shift;
        print "ko\n";
        print "Match: <\n", $self->match, "\n>\n";
        print "Before: <", $self->before, ">\n";
        print "After: <", $self->after, ">\n";
        exp_continue;
        }]
  );
print "closing\n";
$e->clear_accum();
$e->close();

the rec is a simple c program chat echoes what it receives for debug purpose and prints only some command taking the # away. The actual program I want to control needs that # I cannot make without it.

user1708042
  • 1,740
  • 17
  • 20
  • 1
    It works fine here, using Perl 5.29.3, and Expect.pm version 1.35. I checked that a sent `#` sign was received correctly by a spawned process, no need to escape it. – Håkon Hægland Apr 04 '19 at 16:54
  • 2
    Please provide a minimal, *runnable* demonstration of your problem. Specifically, could you provide a short Perl program that use in lieu of `./rec` that demonstrates your problem? – ikegami Apr 04 '19 at 17:31
  • the rec perl equivalent is this oneliner: print "$_\n" while(); and it is so simple just for debugging – user1708042 Apr 04 '19 at 18:07
  • the expect is the latest 1.35, installed by hand locally with the dependencies (IO/Pty and IO/Tty version 1.12). I guess the issue is the old perl I cannot change. Or in how I compiled the Pty/Tty locally. Besides on other machine with perl 5.26 it works fine (thanks @Håkon Hægland ), pity I cannot use that. – user1708042 Apr 04 '19 at 18:35

0 Answers0