There are at least a couple of questions here...

  1. How do I capture STDERR from a shell command?
  2. How do I install NET::SFTP?

First, STDERR. There are multiple ways to do it. As you've already seen, you'll want to play with file descriptors. This text assumes the presence of a simple script in the same directory:

#!/usr/bin/perl for (1 .. 10) { print "printing $_\n"; warn "warning $_\n"; }

If you want both STDOUT and STDERR then you can merge them together and check the combined output.

#!/usr/bin/perl use strict; use warnings; my $stdout_mixed_with_stderr = `perl print_and_warn.pl 2>&1`; print "BEGIN\n\n$stdout_mixed_with_stderr\nEND\n"; # output below __END__ BEGIN warning 1 warning 2 warning 3 warning 4 warning 5 warning 6 warning 7 warning 8 warning 9 warning 10 printing 1 printing 2 printing 3 printing 4 printing 5 printing 6 printing 7 printing 8 printing 9 printing 10 END

If you don't care about STDOUT, you can just capture STDERR instead and throw away STDOUT.

#!/usr/bin/perl use strict; use warnings; my $stdout_mixed_with_stderr = `perl print_and_warn.pl 3>&1 2>&3 3>&- +1>&-`; print "BEGIN\n\n$stdout_mixed_with_stderr\nEND\n"; # output below __END__ BEGIN warning 1 warning 2 warning 3 warning 4 warning 5 warning 6 warning 7 warning 8 warning 9 warning 10 END

If you want both separately, your best bet is probably to redirect STDOUT to one file and STDIN to another file, then read them in.

This is also a FAQ, and the FAQ provides different answers. See How can I capture STDERR from an external command?. There are also CPAN modules which provide interfaces for interacting with other processes.

OK, enough about that. Your other question was how to install NET::SFTP. Your best bet here is to let a CPAN client do the lifting for you. Read a bit and see which of the following might work for you... CPAN, CPANPLUS, App-cpanminus.


In reply to Re: Having trouble getting sftp to work by perlpie
in thread Having trouble getting sftp to work by dirtdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.