Cannot write to fifo

--000e0cd18720616a0904aba61054
Content-Type: text/plain; charset=ISO-8859-1

How can I open multiple FIFO files in perl and print to them simultaneously

I tried a simple script does not work


#!/usr/bin/perl
use strict;

use IO::File;
$|=1;
system("rm -f /tmp/fifo1;mkfifo /tmp/fifo1");
open (OUT,"> /tmp/fifo1") || die;
for (0 .. 10){
print "Hi $_\n";
print OUT "Hi $_\n";

}
close OUT;

--000e0cd18720616a0904aba61054--
Ramprasad Prasad [ Mo, 29 August 2011 16:53 ] [ ID #2063757 ]

Re: Cannot write to fifo

On 8/29/11 Mon Aug 29, 2011 7:53 AM, "Ramprasad Prasad"
<ramprasad.ap [at] gmail.com> scribbled:

> How can I open multiple FIFO files in perl and print to them simultaneously

The program below only opens one FIFO. Is your problem related to opening
multiple FIFOs or opening one FIFO?

> I tried a simple script does not work

"Does not work" is not a helpful description of the problem. It would help
if you could tell us exactly what happens when you run your program. Cut and
paste the actual error messages, if any, that you are getting into your
post.

>
>
> #!/usr/bin/perl
> use strict;
>
> use IO::File;
> $|=1;
> system("rm -f /tmp/fifo1;mkfifo /tmp/fifo1");
> open (OUT,"> /tmp/fifo1") || die;
> for (0 .. 10){
> print "Hi $_\n";
> print OUT "Hi $_\n";
>
> }
> close OUT;

This program creates, opens, and writes to a FIFO. This program should block
on writing to the FIFO until there is a corresponding reading process that
reads from the FIFO. Is there another program reading the FIFO?

See 'perldoc perlipc' and search for "Named Pipes". You will learn there
that there is no need to create a new process to create the FIFO, as you can
use the POSIX module and its mkfifo function.



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Jim Gibson [ Mo, 29 August 2011 18:58 ] [ ID #2063758 ]
Perl » gmane.comp.lang.perl.beginners » Cannot write to fifo

Vorheriges Thema: loop break condition
Nächstes Thema: Problem installing perl module