I'm attempting to write a wrapper for some external programs that I'll be calling from a Perl script.
I need to capture all the inputs and outputs - STDERR being the most important.
After looking through The Camel and around the Monastery, I found IPC::Open3.
I've already looked at the following nodes, but I'm still unable to get a script that performs as I expect:
For testing purposes I'm just using a simple Perl script as the command to be run by open3(), rather than using the binary. I've also tried using cat as well.
This script is as follows:
#!/usr/local/bin/perl # Test script to write to STDOUT # and STDERR. use warnings; use strict; print STDOUT "StdOut!\n"; print STDERR "StdErr!\n";
The main script (using IPC::Open3) is:
I'm expecting this script to write the output from my test.pl script to output.log and errors from the test script to error.log, however both files are created, but empty.#!/usr/local/bin/perl # Script to test IPC::Open3 # Runs, displays $pid to STDOUT, but opened # files are empty. use strict; use warnings; use diagnostics; use IPC::Open3; $|++; my $cmd = "/home/baz/test.pl"; open(ERRLOG, ">error.log") or die "Can't open error log! $!"; open(OUTPUT, ">output.log") or die "Can't open output log! $!"; my $pid = open3(\*STDIN, \*OUTPUT, \*ERRLOG, $cmd) or die "$!"; print "PID was $pid\n"; close(ERRLOG) or die "Can't close filehandle! $!"; close(OUTPUT) or die "Can't close filehandle! $!";
Have I got the wrong end of the stick somewhere?
In reply to IPC::Open3 woes by BazB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |