cyberconte has asked for the wisdom of the Perl Monks concerning the following question:

Basically, what i have is this:
my $prog = new IO::File "| $ldapadd -x 2>&1" or die "Unable to open $ldapadd: $!";
What i want to do is to read hte output from ldapadd after piping in my stuff - however adding a pipe to the end of it doesn't seem to have any effect (i.e. it doesn't become read/write, its still write-only, and all output is dumped to the terminal). Is there an easy way to do the equivilant of this:
my $prog = new IO::File "| $ldapadd -x 2>&1 |" or die "Unable to open $ldapadd: $!";

Replies are listed 'Best First'.
Re: Input and output piping?
by ctilmes (Vicar) on Apr 22, 2003 at 20:27 UTC
    Take a look at IPC::Open2 (or IPC::Open3). As the man page says:
    It's what you think should work when you try $pid = open(HANDLE, "|cmd args|");
Re: Input and output piping?
by jasonk (Parson) on Apr 22, 2003 at 20:40 UTC

    In addition to IPC::Open2, you might want to consider using one of the many LDAP modules on CPAN, rather than running ldapadd externally.


    We're not surrounded, we're in a target-rich environment!
Re: Input and output piping?
by vek (Prior) on Apr 22, 2003 at 23:13 UTC
    cyberconte I use IPC::Open2 and I think you'll find that it's exactly what you're looking for. FWIW I regularly use it on one of our legacy machines to send STDIN to and receive STDOUT from COBOL programs and it works like a charm :-)

    -- vek --