in reply to Perl won't Open() when called from Java

Well first of all: 'no warnings "all";' this is not a good idea. I would "use warnings;". Might learn something useful from these warnings! Of course, print the variable $syslog_file before you use it - probably some big clue there as to why the open() doesn't work!

Update: Oh, I see that you do print $syslog_file. Look for leading/trailing white space characters in this. A newline or something like that might be causing the trouble.

Another update: Add $|=1; to the code. This turns off buffering to STDOUT. You may be actually reaching past the open(), but just can't see the message that this happened. Or alternatively, print to STDERR which is by default un-buffered.

  • Comment on Re: Perl won't Open() when called from Java

Replies are listed 'Best First'.
Re^2: Perl won't Open() when called from Java
by Anonymous Monk on Feb 23, 2012 at 19:33 UTC

    I was able to fix this but can't understand why. I replaced:

    my $syslog_file = "tail -n 0 -f /var/log/messages | "; print STDOUT "some debug line: $syslog_file\n"; open(FH,"syslog_file") print STDOUT "didn't reach before\n";

    with:

    my $syslog_file = "tail -n 0 -f /var/log/messages | "; print STDERR "some debug line: $syslog_file\n"; open(FH,"syslog_file") print STDERR "reaches now\n";

    Why would changing to STDERR make a difference?

      Oh I see. STDERR is unbuffered, but STDOUT buffers. Thanks!
        Yes, that's right. A typical value for the buffer would be 4K. Mileage varies of course! But it it is completely conceivable that since the program is "hung" that there are unprinted things in the buffer.
Re^2: Perl won't Open() when called from Java
by JavaFan (Canon) on Feb 23, 2012 at 19:44 UTC
    Considering that $syslog_file is assigned a string literal, without any interpolation, I don't think the OP should expect any surprises here.

    And neither should we.

      my $syslog_file = "tail -n 0 -f /var/log/messages |"; doesn't look like a string_literal to me. yes this is...was thinking incorrectly. When I looked at the code, by the time I got to the open(), I was thinking that the op had done a system call to get the output of tail. My goof. But it appears that my $|=1; suggestion did work.