gabrielsousa has asked for the wisdom of the Perl Monks concerning the following question:

can i print the $out before the finish

my @cmd=('lftp', '-u', "$user,$pass", '-e', "open", "$host"); my $h = start \@cmd, \$in, \$out, \$err, timeout( 10 ); $in .= "ls\n"; pump $h; print $out; finish $h;

Replies are listed 'Best First'.
Re: IPC::Run - can i print the $out before the finish
by haukex (Archbishop) on Jan 25, 2017 at 17:56 UTC

    Hi gabrielsousa,

    The documentation I linked you to contains example code that shows how to interact with smbclient, which should be very similar to interacting with an FTP client. It shows how to use a while loop to continually call pump until the next prompt is seen.

    Regards,
    -- Hauke D

      manage to make it work, thanks
      my ($user,$pass,$host,$in,$out,$err)=('eurotuxftpprod','KujRemebeuj0', +"$ARGV[0]","","",""); use IPC::Run qw( start pump finish timeout ); my @cmd=('lftp', '-u', "$user,$pass", '-e', "open", "$host"); my $h = start \@cmd, \$in, \$out, \$err, timeout( 5 ); $in .= "cls -1\n"; pump $h until $out || $err; # =~ /input/ ; print $out; $out = '' ; $in .= "ls\n"; pump $h until $out || $err; # =~ /input/ ; print $out; $out = '' ; $in .= "mget *\n"; pump $h until $out || $err; # =~ /input/ ; print $out; print $err; finish $h;
      manage to make it working. have a strange thing, the output is always of the first command :(
      what i'm doing wrong
      use IPC::Run qw( start pump finish timeout new_chunker); my @cmd=('lftp', '-u', "$user,$pass", '-e', "open", "$host"); #my $h = start \@cmd, \$in, \$out, \$err, timeout( 5 ); my $h = start \@cmd, \$in, '>' => new_chunker, sub { push @out, @_ }, + timeout( 5 ); $in = "cls -1\n"; pump $h until @out; print @out; $in = "ls\n"; pump $h until @out; print @out; print @out; finish $h;
Re: IPC::Run - can i print the $out before the finish (code-tags) (updated)
by LanX (Saint) on Jan 25, 2017 at 17:07 UTC