Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

IPC::Run - can i print the $out before the finish

by gabrielsousa (Sexton)
on Jan 25, 2017 at 16:55 UTC ( #1180309=perlquestion: print w/replies, xml ) Need Help??

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 (Bishop) 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 (Sage) on Jan 25, 2017 at 17:07 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1180309]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2021-09-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?