in reply to Net:SSH::Expect and microcom?

Using Net::OpenSSH and Expect:
# untested use Net::OpenSSH; my $ssh = Net::OpenSSH->new(...); my ($pty, $pid) = $ssh->open2pty('microcom /tmp/dev/mux1'); my $exp = Expect->init($pty); $exp->send("AT+CSQ\r\n"); $exp->expect($timeout, [qr/^OK$/ => sub { ... }], [qr/^ERROR$/ => sub { ... }]); $exp->soft_close(); waitpid($pid, 0);

Replies are listed 'Best First'.
Re^2: Net:SSH::Expect and microcom?
by Anonymous Monk on Nov 08, 2011 at 12:05 UTC

    Thanks, but it doesnt work. I am experiencing some very odd behaviour with the suggested snipped.

    When run manually, the AT command returns to OK within 500ms. Since the RegEx would match and it still times out, I believe it safe to conclude that it still doesnt pass in the AT command.

    More important is the fact that no matter what timeout I set, it throws the warning after ~2 seconds. I've set 50 seconds in the example below:

    print "Before timeout: " . localtime() . "\n"; my $timeout = 50; $exp->expect($timeout, [qr/^OK$/ => sub { print "Success!\n"; }], [qr/^ERROR$/ => sub { print "Failure!\n"; }]) or warn "Timeout!"; print "After timeout: " . localtime() . "\n";
    and the output I get from the above:
    Before timeout: Tue Nov 8 03:31:02 2011 Timeout! at getdbm.pl line 18. After timeout: Tue Nov 8 03:31:04 2011

    Am I experiencing a bug here, or am I (still) an idiot?

      Maybe you have to wait for microcom to settle before sending anything. Try sleeping for 1 second before sending the modem command.

        No luck - it sleeps for 5 seconds an continue - if anything, it made the issue of timeout not being honoured even worse:

        Before timeout: Tue Nov 8 04:14:40 2011 Timeout is: 500 Timeout! at getdbm.pl line 20. After timeout: Tue Nov 8 04:14:40 2011