in reply to Re^4: How to capture error messages... (shell quoting recipe)
in thread How to capture error messages...

In this case, this can be done by using the multi-argument pipe-open

No, you can't. You took out the 2>&1, reintroducing the problem the OP was trying to solve. I'd use IPC::Open3 to redirect STDERR without involving the shell.

Replies are listed 'Best First'.
Re^6: How to capture error messages...
by ambrus (Abbot) on Jan 17, 2008 at 08:42 UTC

    Oh, sorry. I didn't notice that.

    In that case, let me modify the above code like this (untested):

    my $resultLdapSearch; { defined(my $pid = open my $P, "-|") or die "error forking ldapmodify: +$!"; if (!$pid) { open STDERR, ">&STDOUT" or die "error dup2ing stdout to stderr"; exec "ldapmodify", "-h", $ldap_server, "-D", "cn=Directory Manager +", "-w", $dir_mgr_pwd, "-f", $ldap_modify_file or die "cannot exec ldapmodify: $!"; die; # just to be sure } local $/ = undef; defined($resultLdapSearch = <$P>) or die "error reading from pipe: $!"; close $P or die $! ? "error closing pipe: $!" : "ldapmodify exitted with a nonz +ero exit status: $?"; }