print to STDOUT works but FH1 does not with FIFO named pipe

R

Rocky

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";
}
}
 
S

Sherm Pendley

Rocky said:
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--
 
R

Rocky

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
 
R

Rocky

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";
 
P

Paul Lalli

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

A. Sinan Unur

???
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:

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

Paul Lalli

???
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
 
R

Rocky

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


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.


Please fix your indenting. Read:
perldoc perlstyle



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


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
 
P

Paul Lalli

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
 
R

Rocky

Check your posting carefully:


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
 
P

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

As I said in my last post, show us your code. We can't debug something on
your assertion that it should work. We have to see the actual code you're
using. Show us the code that you think should work, but does not.

Paul Lalli
 
R

Rocky

Bit of a stretch that, but not your words.

For a typist to type a grave accent, she (typical typist gender)
must stretch her little finger upward and leftward, quite a good
distance, while keeping her left index finger on the f key, and
if limber, both left thumb and right thumb pressed against the
bottom edge of her spacebar.

It is very difficult to accidently type the least noticable key,
a grave accent, even if typical masculine index finger poking
style typing.

Last character typed is a semicolon, next would be Enter, with
both on the far right edge of keyboard standard keys. To
suddenly stretch upward and to the left, illogical and
rather suggestive; very difficult to be accidental, even
for BoBo The Clown.


Purl Gurl

Not a typo -- a feature of my broken keyboard -- free `backticks` every
few hundred characters it is 6 years old but I like it because it has
"clicky keys" that make me sound like a good typist
 
R

Rocky

As I said in my last post, show us your code. We can't debug something on
your assertion that it should work. We have to see the actual code you're
using. Show us the code that you think should work, but does not.

Paul Lalli

so posted sir.

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

A. Sinan Unur

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

Well, especially since you seemed to be aware of your keyboard's tendency
to produce extra unwanted characters, maybe you should have checked your
post for those characters before claiming you could see nothing in your
posted code that would have caused the error message noted by Purl Gurl.

BTW, your attitude does not work in your favor.
 
M

Matt Garrish

Purl Gurl said:
Noticeable noticable, a hazard of typing at
Warp 9 speed.

Doesn't say much for your English skills if that is the only error you think
is worth correcting.

Matt

p.s. If you want to know why you never see your students again after the
first lesson, it's because one lesson is enough to establish that they know
more than the teacher.
 
M

Matt Garrish

Rocky said:
so posted sir.

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

Are you closing the filehandles? That would be my guess as to why you aren't
seeing any output in the files.

Matt
 
R

Rocky

Well, especially since you seemed to be aware of your keyboard's tendency
to produce extra unwanted characters, maybe you should have checked your
post for those characters before claiming you could see nothing in your
posted code that would have caused the error message noted by Purl Gurl.

BTW, your attitude does not work in your favor.


*this thread has not worked in my favor either*

I have checked out a few of the posters to this thread on google and you all seem to be very
intelligent people. Most instruct or teach in some form or another. Yet
you waste time and energy picking on the smallest error as though you were
larry wall himself. Please do not help me if that is your attitude.
There are 15 posts in this thread already and no one has addressed the
question that I have asked. There are many people who
really want to help. You sir, do not seem to be one. So to you I say
this. Cornell sucks because it produces people like you
 
A

A. Sinan Unur

so posted sir.

#!/usr/bin/perl
use warnings;
use strict;
$| = 1;

I do not think there is any point to this. You are not printing anything
to STDOUT.
#open(FH3,"</var/run/syslogdpipe") or die "$!\n";

Check the difference between

die "Error: $!\n";

and

die "Error: $!";

Most of the time, it is better not to use the newline.
open(FH3,"</storage/tempmail") or die "$!\n";
open(FH1,">./mx0out") or die "$!\n";
open(FH2,">./mx1out") or die "$!\n";
while (<FH3>)
{
my $line = $_;


The idiom for this is

while(my $line = said:
if ($line =~ /^.*svr-linux.*$/)
{
print FH1 "mx00 $line\n";
}
elsif ($line =~ /^.*192\.168.*$/)
{
print FH2 "mx01 $line\n";
}
}

Please post properly formatted code.

use warnings;
use strict;

open my $fh1, '>', './mx0out' or die $!;
open my $fh2, '>', './mx1out' or die $!;

while( <DATA> ) {
if( /^.*svr-linux.*$/ ) {
print $fh1 "mx00 $_";
} elsif( /^.*192\.168.*$/ ) {
print $fh2 "mx01 $_";
}
}

close $fh2 or die $!;
close $fh1 or die $!;

__DATA__
sayudtauysdtyutasdsvr-linuxsaldfjksdfj
ksjadhfuysdtyutasdsvr-linuxsaldfjksdfj
sayudtaskjdfhutasdsvr-linuxsaldfjksdfj
192.168.1.1
192.168.1.2
34.234.32.4

C:\Home> ttt.pl

C:\Home\> cat mx0out
mx00 sayudtauysdtyutasdsvr-linuxsaldfjksdfj
mx00 ksjadhfuysdtyutasdsvr-linuxsaldfjksdfj
mx00 sayudtaskjdfhutasdsvr-linuxsaldfjksdfj

C:\Home> cat mx1out
mx01 192.168.1.1
mx01 192.168.1.2
 
A

A. Sinan Unur

I am going to rearrange this post a little bit to clarify what happened
here.

To which you responded

I pointed out to you what was causing the error message about which you
seemed to be confused.

If your response to that is:

Yet you waste time and energy picking on the smallest error
as though you were larry wall himself. Please do not help
me if that is your attitude. There are 15 posts in this thread
already and no one has addressed the question that I have asked.
There are many people who really want to help. You sir, do not
seem to be one. So to you I say this. Cornell sucks because it
produces people like you

I am happy as long as they pay my salary.
 
R

Rocky Allen

I am going to rearrange this post a little bit to clarify what happened
here.


To which you responded


I pointed out to you what was causing the error message about which you
seemed to be confused.

If your response to that is:



I am happy as long as they pay my salary.


Yeah, I guess that is what it's all about.

your results in the other section of this thread duplicate mine exactly.
The problem does not occurr when I read in a file. It occurrs when I read
from a named pipe which is what /var/run/syslogdpipe is. Anyway, thank
you for your help and have a great day. It might be faster just to read
the book. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top