Portál AbcLinuxu, 10. května 2025 05:28
#!/usr/bin/perl
use IO::Handle;
system("rm pipe");
system("mkfifo pipe");
unless ($pid = fork()) {
&input;
}else{
&output;
}
sub input {
$FILE = "pipe";
open(my $log, '>>', $FILE);
while(1){
$log->autoflush(0);
print $log "XXX";
}
}
sub output {
open (READER, "pipe");
while(1){
@raw_data=<READER>;
print $raw_data[0];
}
}
use strict; use IO::Handle; my $pipe = 'pipe'; my $pid; system("rm $pipe"); system("mkfifo $pipe"); unless ($pid = fork()) { &input; } else { &output; } sub input { my $log; my $count = 10; open($log, '>>', $pipe) or die $!; $log->autoflush(0); while($count > 0){ print $log "test ", $count--, "\n"; } close($log); } sub output { my $line; open(READER, '<', $pipe) or die $!; while($line = <READER>){ print $line; } close(READER); }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.