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

how i get stdout from this:
to store in $var
open( my $LFTP,'|-', "lftp -u $user,$pass -e open $host " ) || die "Ca +nnot open lftp: $!"; print $LFTP <<"END"; ls END

Replies are listed 'Best First'.
Re: feeding stdin of executed command and store stdout in $var
by Corion (Patriarch) on Jan 25, 2017 at 13:32 UTC
      i want to list the ftp, and than download some files, not all
      after de "ls" i want to send other command
      but before send other command i want to read what files are in ftp

        Thank you for clarifying what you intend to do.

        Have you tried using Net::FTP instead of lftp? In what way was it unsuitable for your needs?

Re: feeding stdin of executed command and store stdout in $var
by haukex (Archbishop) on Jan 25, 2017 at 13:55 UTC

    Hi gabrielsousa,

    Like Corion, I'd strongly recommend using a Perl module like Net::FTP. If however for some reason you really need to talk to an external program, I can recommend IPC::Run, or perhaps Expect.

    Regards,
    -- Hauke D

      how i send several commands with IPC::run ?

        Hi gabrielsousa,

        how i send several commands with IPC::run ?

        IPC::Run's interface takes a little bit of getting used to, but have a look at the doc and example code of the pump() function.

        Regards,
        -- Hauke D