Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't my Java program read Perl's STDERR?

Tags:

java

stderr

perl

We have a Perl program to validate XML which is invoked from a Java program. It is not able to write to standard error and hanging in the print location.

Perl is writing to STDERR and a java program is reading the STDERR using getErrorStream() function. But the Perl program is hanging to write to STDERR. I suspect Java function is blocking the STDERR stream completely and Perl is waiting for this stream to be released.

Is there a way in Perl to overcome this blockage and write to standard error forcefully? Since Java is doing only a read the API should not be locking the STDERR stream as per java doc.

Perl Code snippet is:

sub print_error
{
    print STDERR shift;
}

Java code snippet is:

while ( getErrorStream() != null )
{
    SOP errorMessage;
}

Appreciate the help in advance.

Thanks, Mathew Liju

like image 836
Liju Mathew Avatar asked Dec 10 '08 07:12

Liju Mathew


1 Answers

getErrorStream does not read the error stream, it just obtains a handle to it. As it's a pipe, if you never actually read it, it will fill up and force the Perl program to block.

You need something like:

Inputstream errors = getErrorStream();
while (errors.read(buffer) > 0) {
    SOP buffer;
}
like image 128
Adrian Pronk Avatar answered Oct 23 '22 09:10

Adrian Pronk