in reply to Redirecting and using output from executed program

Two ways of doing this might be the shell redirect method

# @exec has the commad that i wish to run # but we're throwing away the error meesages open (T_RES,"@exec 2>/dev/null |") or die "Unable to fork '@exec': $!"; while (<T_RES>) { # parsing the output }
and the Perl IPC method
# @exec has the commad that i wish to run use IPC::Open3 my $pid; $pid = open (WTR,T_RES,ERR,"@exec") or die "Unable to fork '@exec': $!"; while (<T_RES>) { # parsing the output } waitpid $pid, 0; # if necessary, see below

Thought the shell method might be easier, the IPC::Open3 method might be more portable.

Note:
With the IPC::Open3 method, you might have to waitpid to reap the process.

Hope that helped,
-v
"Perl. There is no substitute."

Replies are listed 'Best First'.
Re^2: Redirecting and using output from executed program
by DrHyde (Prior) on Sep 30, 2004 at 16:50 UTC
    Or if you want to keep STDERR, 2>&1 instead of 2>/dev/null would be nice. This may be sensitive to your choice of shell.

    Also try the IO::Capture modules.