Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Output from nested scripts 1

Status
Not open for further replies.

mwhamilton

Technical User
Jan 28, 2002
11
US
Hi,
I am having a problem with my output. I have one perl script that is doing some file reading. It has to call a separate script with the system function that does some conversions on the data. My problem is that when the called script prints error messages to the std output, it does not actually get to the display, and I therefore do not ever see the error messages. Is there any way to force print statements to print to the stdout even when called from inside another script? Thanks.
 
The system function should display all STDOUT from the called command. Maybe the command's output is going to standard error. To attach STDERR to STDOUT on a Unix system:
Code:
system("myscript 2>&1");
The following will allow you to run a command and print the output after the command is finished:
Code:
$out = `myscript 2>&1`;
print $out;
The following will allow you to print and save the command's output while it is running:
Code:
open(PIPE, "myscript 2>&1 |") or die "Can't open pipe from myscript: $!\n";
while(<PIPE>) {
    print $_;
    push(@out, $_); # save output in array
}
close(PIPE);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top