in reply to Re: Another system redirect problem
in thread Another system redirect problem

I believe IPC::Run provides a solution
# Can do I/O to sub refs and filenames, too: run \@cmd, '<', "in.txt", \&out, \&err or die "cat: $?" run \@cat, '<', "in.txt", '>>', "out.txt", '2>>', "err.txt";

Replies are listed 'Best First'.
Re^3: Another system redirect problem
by ikegami (Patriarch) on Jun 18, 2011 at 09:38 UTC

    From what I gathered from the docs and a lot of testing, it would look like

    use IPC::Run qw( run ); open(my $fh, '>>', '/Volumes/Expansion Drive/stuffTGZ/list_xxx_dirs.tx +t') or die $!; print($fh "-------------------------------------------------\n"); print($fh "- $File::Find::name -----------------------------\n"); run [ "/bin/ls" => ( "-l", $File::Find::name ) ], '<', \"", '>', $fh;

    Notes:

    • Lexical file handles work, but I didn't see it in the documentation.
    • «'<', \""» appears to open /dev/null (desirable) as opposed to closing STDIN as documented (undesirable).
    • The child appears to inherit the parent's STDERR if 2> isn't specified. That's probably documented, but I didn't see it.