Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   print to STDOUT works but FH1 does not with FIFO named pipe (http://www.velocityreviews.com/forums/t887270-print-to-stdout-works-but-fh1-does-not-with-fifo-named-pipe.html)

Rocky 07-14-2004 05:20 PM

print to STDOUT works but FH1 does not with FIFO named pipe
 
hello everyone. I have a problem and I need assistance. this script
prints output to STDOUT just fine but for some reason will no print to FH1
or FH2. I am wondering if it prints the data to memory then writes it out
to the file at close.

#!/usr/bin/perl
use warnings;
use strict;
open(FH3,"</var/run/syslogdpipe") or die "$!\n"; #this is a fifo
open(FH1,">./mx0out");`
open(FH2,">./mx1out");
while (<FH3>)
{
my $line = $_;
if ($line =~ /^.*svr-linux.*$/)
{
print "mx00 $line\n";
}
elsif ($line =~ /^.*192\.168.*$/)
{
print "mx01 $line\n";
}
}


Sherm Pendley 07-14-2004 05:34 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
Rocky wrote:

> hello everyone. I have a problem and I need assistance. this script
> prints output to STDOUT just fine but for some reason will no print to FH1
> or FH2.


> open(FH1,">./mx0out");
> open(FH2,">./mx1out");


Always, *always* check the return value from open().

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Rocky 07-14-2004 06:05 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004 10:48:24 -0700, Purl Gurl wrote:

> Rocky wrote:
>
>> I have a problem and I need assistance.

>
> Can't find string terminator "`" anywhere before EOF at test.pl line 6.
>
>
> Purl Gurl

???
Is that an error that you get while trying to run the script? I do not
get the same thing and I can see no place where it might occurr. Please
explain.
thank you,
Rocky

Rocky 07-14-2004 06:08 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004 13:34:10 -0400, Sherm Pendley wrote:

> Rocky wrote:
>
>> hello everyone. I have a problem and I need assistance. this script
>> prints output to STDOUT just fine but for some reason will no print to FH1
>> or FH2.

>
>> open(FH1,">./mx0out")or die "$!\n";
>> open(FH2,">./mx1out")or die "$!\n";

>
> Always, *always* check the return value from open().
>
> sherm--

thank you. The files open and the script even works when the input file
is not a named pipe. the script will print to STDOUT when the FH1 and FH2
statements are removed
i.e. print "$line\n"; instead of print FH1 "$line\n";

Paul Lalli 07-14-2004 06:11 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004, Rocky wrote:

> hello everyone. I have a problem and I need assistance. this script
> prints output to STDOUT just fine but for some reason will no print to FH1
> or FH2. I am wondering if it prints the data to memory then writes it out
> to the file at close.


No. Printing is generally line-buffered. That is, the data is printed
after every new-line character.

>
> #!/usr/bin/perl
> use warnings;
> use strict;
> open(FH3,"</var/run/syslogdpipe") or die "$!\n"; #this is a fifo
> open(FH1,">./mx0out");`
> open(FH2,">./mx1out");


Always, always, *always* check the return value of open(), just like you
did for the first open. You have no idea whether or not these files are
actually being opened, or if there was an error of some kind.

> while (<FH3>)
> {
> my $line = $_;


Please fix your indenting. Read:
perldoc perlstyle


> if ($line =~ /^.*svr-linux.*$/)
> {
> print "mx00 $line\n";


You're not printing to the filehandles here. What makes you think any
output should be printed to the files?

> }
> elsif ($line =~ /^.*192\.168.*$/)
> {
> print "mx01 $line\n";
> }
> }


Paul Lalli


A. Sinan Unur 07-14-2004 06:13 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
Rocky <PerlGuRu2b@bobotheclown.org> wrote in
news:pan.2004.07.14.17.56.59.675303@bobotheclown.o rg:

> On Wed, 14 Jul 2004 10:48:24 -0700, Purl Gurl wrote:
>
>> Rocky wrote:
>>
>>> I have a problem and I need assistance.

>>
>> Can't find string terminator "`" anywhere before EOF at test.pl line
>> 6.
>>
>> Purl Gurl

> ???
> Is that an error that you get while trying to run the script? I do
> not get the same thing and I can see no place where it might occurr.
> Please explain. thank you,
> Rocky


Check your posting carefully:

>>> open(FH1,">./mx0out");`


See those few pixels at the end of the line ... That's an extra
character.

--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)


Paul Lalli 07-14-2004 06:14 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004, Rocky wrote:

> On Wed, 14 Jul 2004 10:48:24 -0700, Purl Gurl wrote:
>
> > Rocky wrote:
> >
> >> I have a problem and I need assistance.

> >
> > Can't find string terminator "`" anywhere before EOF at test.pl line 6.
> >
> >
> > Purl Gurl

> ???
> Is that an error that you get while trying to run the script? I do not
> get the same thing and I can see no place where it might occurr. Please
> explain.
> thank you,
> Rocky


In your post, you accidentally typed a ` character after line 6 of the
code. It clearly does not belong there.

If you re-typed your code into the post, don't do that. Always copy &
paste your actual code.

Paul Lalli

Rocky 07-14-2004 06:31 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004 14:11:44 -0400, Paul Lalli wrote:

> On Wed, 14 Jul 2004, Rocky wrote:
>
>> hello everyone. I have a problem and I need assistance. this script
>> prints output to STDOUT just fine but for some reason will no print to FH1
>> or FH2. I am wondering if it prints the data to memory then writes it out
>> to the file at close.

>
> No. Printing is generally line-buffered. That is, the data is printed
> after every new-line character.
>
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> open(FH3,"</var/run/syslogdpipe") or die "$!\n"; #this is a fifo
>> open(FH1,">./mx0out");`
>> open(FH2,">./mx1out");

>
> Always, always, *always* check the return value of open(), just like you
> did for the first open. You have no idea whether or not these files are
> actually being opened, or if there was an error of some kind.
>
>> while (<FH3>)
>> {
>> my $line = $_;

>
> Please fix your indenting. Read:
> perldoc perlstyle
>
>
>> if ($line =~ /^.*svr-linux.*$/)
>> {
>> print "mx00 $line\n";

>
> You're not printing to the filehandles here. What makes you think any
> output should be printed to the files?
>
>> }
>> elsif ($line =~ /^.*192\.168.*$/)
>> {
>> print "mx01 $line\n";
>> }
>> }

>
> Paul Lalli


My mistake. I left the FH1 and FH2 out of the posted code. When I run
this script and just print it to standard out the data will stream
perfectly as it comes in from the FIFO. If I print it to FH1,FH2 and tail
-f the output files I get nothing. That, I guess, is what I should have
said from the beginning
thank you,
Rocky


Paul Lalli 07-14-2004 06:39 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004, Rocky wrote:

> On Wed, 14 Jul 2004 13:34:10 -0400, Sherm Pendley wrote:
>
> > Rocky wrote:
> >
> >> hello everyone. I have a problem and I need assistance. this script
> >> prints output to STDOUT just fine but for some reason will no print to FH1
> >> or FH2.

> >
> >> open(FH1,">./mx0out")or die "$!\n";
> >> open(FH2,">./mx1out")or die "$!\n";

> >
> > Always, *always* check the return value from open().
> >
> > sherm--

> thank you. The files open and the script even works when the input file
> is not a named pipe. the script will print to STDOUT when the FH1 and FH2
> statements are removed
> i.e. print "$line\n"; instead of print FH1 "$line\n";



Post your full, runnable code that is showing the error. Do not post code
that tells us "this works, but if you change ____, it stops." Show us the
code that doesn't work.

Paul Lalli

Rocky 07-14-2004 07:10 PM

Re: print to STDOUT works but FH1 does not with FIFO named pipe
 
On Wed, 14 Jul 2004 18:13:37 +0000, A. Sinan Unur wrote:

> Rocky <PerlGuRu2b@bobotheclown.org> wrote in
> news:pan.2004.07.14.17.56.59.675303@bobotheclown.o rg:
>
>> On Wed, 14 Jul 2004 10:48:24 -0700, Purl Gurl wrote:
>>
>>> Rocky wrote:
>>>
>>>> I have a problem and I need assistance.
>>>
>>> Can't find string terminator "`" anywhere before EOF at test.pl line
>>> 6.
>>>
>>> Purl Gurl

>> ???
>> Is that an error that you get while trying to run the script? I do
>> not get the same thing and I can see no place where it might occurr.
>> Please explain. thank you,
>> Rocky

>
> Check your posting carefully:
>
>>>> open(FH1,">./mx0out");`

>
> See those few pixels at the end of the line ... That's an extra
> character.

Indeed it is. Thank you for pointing that out. Please forgive me.
you have cracked the case. My compliments on a job well done. Cornell
sucks



All times are GMT. The time now is 11:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.