Use backticks (or the qx// quoting mechanism) to launch the program and capture its output. You can obtain the exit code in the variable $?. It requires a bit of munging to pull out the three pieces of information it encodes. See perlvar for more information. The following code should help you get started.
#! /usr/bin/perl -w my @output = `@ARGV`; print "Error code is $?\nOutput is ", @output, "\n";
Run it with the name of the command (and its arguments) you want to execute. If the command you want to run requires its own redirections, or if you need to capture both the standard output and error streams, things get considerably trickier. It can be done albeit with a bit more code.
- another intruder with the mooring of the heat of the Perl
In reply to Re: how can I redirect the output of a program and get the exit code too?
by grinder
in thread how can I redirect the output of a program and get the exit code too?
by vikee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |