1

I have a program which reads the output from external application.The external app gives set of output. My program reads the output from this external app while($line=<handle to external app>) and print it to STDOUT.But the "print $line STDOUT" prints only some lines and when the error has occurred ,print to STDOUT is not working , but my one more logging statement "push @arr,$line" has stored complete output from the external app.From this i got to know STDOUT is not working properly when error happens.

Eg: if external app output is like:


Starting command
First command executed successfully    
Error:123 :next command failed    
Program terminated

In here the STDOUT prints only :

Starting command
First command executed successfully

But if I check the array it has complete output including error details. So I guessed STDOUT has been redirected or lost.

So I tried storing STDOUT in the beginning of the program to $old_handle using open and then try to restore it before print statement using select($old_handle) (thinking some thing redirects STDOUT when error happens)

But I was not successfull, I don't know what is wrong here. Please help me.

ann
  • 576
  • 1
  • 10
  • 19
any01
  • 1
  • 1
  • Why is this question community wiki? some people might be discouraged from answering because upvotes will not give them any reputation. – Ether Jun 22 '10 at 16:13

2 Answers2

1

It's possible the output is being buffered. Try setting

$| = 1;

at the start of your program. This will cause the output to be displayed straight away, rather than being buffered for later.

psmears
  • 26,070
  • 4
  • 40
  • 48
0

Just guess, may be because error output doesn't go to STDOUT. Use redirect

first_program |& perl_program

or

first_program 2>&1 | perl_program
Hynek -Pichi- Vychodil
  • 26,174
  • 5
  • 52
  • 73