Thread Programm soll die eigene Ausgabe lesen (5 answers)
Opened by ronald at 2003-12-19 11:07

ronald
 2003-12-19 14:55
#76603 #76603
User since
2003-08-15
76 Artikel
BenutzerIn
[default_avatar]
Hat sich erledigt.
Es war doch im Cookbook:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Filtering Your Own Output
Problem
You want to postprocess your program's output without writing a separate program to do so.

Solution
Use the forking form of open to attach a filter to yourself. For example, this will restrict your program to a hundred lines of output:

head(100);
while (<>) {
   print;
}

sub head {
   my $lines = shift || 20;
   return if $pid = open(STDOUT, "|-");
   die "cannot fork: $!" unless defined $pid;
   while (<STDIN>) {
       print;
       last unless --$lines;
   }
   exit;
}


Das ist für mein Testprogramm aber nicht brauchbar, weil der geforkte Prozess die ganze Rückgabe nimmt.

Ich habe mich dann doch für den Ansatz von @Relais entschieden (der funktioniert und ist handhabbar).
Vielen Dank an dieser Stelle.

Ronald

View full thread Programm soll die eigene Ausgabe lesen