Another useful option is the Capture::Tiny module, which allows you to capture the output for (possible) later use:
use Capture::Tiny ':all';
my $command = ...;
my @args = ...;
my ($stdout, $stderr, $exit) = capture
{
system($command, @args);
};
Hope that helps,
| [reply] [d/l] |
If you are using system, you could redirect the output to /dev/null:
system 'ls > /dev/null';
If using qx, just discard what is returned:
qx(ls);
| [reply] [d/l] [select] |
There are a number of ways to invoke external applications from Perl, and the general rule is that unless the method you use handles a particular I/O stream (STDIN, STDOUT, STDERR), the child connects to the parent's channel. So, when you use system, the child will use all three if it's looking for something.
The ways to avoid this come down to either redirecting undesirable output to /dev/null, e.g. system 'call > /dev/null 2> /dev/null' or using an approach that captures the stream, like qx/backticks, IPC::Open3 or pipe/fork/exec. Note that backticks only handle STDOUT (as with IPC::Open2), so many people will use an explicit redirection of STDERR with a capture of STDOUT.
For all the gritty details, see perlipc.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] [d/l] [select] |