in reply to Call external script via ssh with Control::CLI, get output to calling script window

Disclaimer: I haven't used Control::CLI before.

With '->cmd()' it seems like you can't. But the documentation says '->cmd()' is equivalent to

$obj->read(Blocking => 0); $obj->print($cliCommand); $output = $obj->waitfor($obj->prompt);

so you may be able to replace the call to cmd() with something like this:

$obj->read(Blocking => 0); $obj->print($cliCommand); while (not $obj->prompt) { my $inc_output = $obj->read(Blocking => 0); if (defined $inc_output) { print $inc_output; $s1_output .= $inc_output; } sleep 1; } (process output in $s1_output)
This code fragment is totally untested. I just wanted to give you an idea.
  • Comment on Re: Call external script via ssh with Control::CLI, get output to calling script window
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Call external script via ssh with Control::CLI, get output to calling script window
by ImJustAFriend (Scribe) on Jul 29, 2015 at 09:10 UTC

    Thanks for the idea, I'll try it out!!

      You can use polling mode on cmd() if you set Blocking to 0

      So you could do this:

      $s1_cli->cmd( Command => "/path/to/pre-loader.pl arg1 arg2 2>&1", Blocking => 0 ); do { Time::HiRes::sleep 0.2; ($ok, $output) = $s1_cli->cmd_poll; print $output if length $output; } until $ok;

      Or else this:

      $s1_cli->cmd( Command => "/path/to/pre-loader.pl arg1 arg2 2>&1", Blocking => 0 ); $s1_cli->poll( Poll_code => sub { $output = ($s1_cli->cmd_poll)[1]; print $output if length $output } );