in reply to Having trouble getting sftp to work

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.