Thread Perl mit Kommandozeilenprogramm kommunizieren (Windows) (79 answers)
Opened by bianca at 2013-09-10 13:07

GwenDragon
 2013-09-13 22:32
#170209 #170209
User since
2005-01-17
14533 Artikel
Admin1
[Homepage]
user image
Ich shet gra selbst etwas im Regen, aber CPAN:IPC::Open3 müsste dafür geeigent sein. Ich sagte ja, ich hab einen schlechten Überblick.

Quelle: Perlmonks:150775
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
my $pid;
eval{
  $pid = open3($infh, $outfh, $errfh, $cmd);
};
die "open3: $@\n" if $@;

print "PID was $pid\n";

my $sel = new IO::Select; # create a select object to notify
                          # us on reads on our FHs
$sel->add($outfh,$errfh); # add the FHs we're interested in

while(my @ready = $sel->can_read) { # read ready
    foreach my $fh (@ready) { 
        my $line = <$fh>; # read one line from this fh
        if(not defined $line){ # EOF on this FH
            $sel->remove($fh); # remove it from the list
            next;              # and go handle the next FH
        }
        if($fh == $outfh) {     # if we read from the outfh
            print OUTPUT $line; # print it to OUTFH
        } elsif($fh == $errfh) {# do the same for errfh  
            print ERRLOG $line;
        } else { # we read from something else?!?!
            die "Shouldn't be here\n";
        }
    }
 }


Wie die Kommunikation ablaufen soll, muss dann wohl im while geregelt werden.
Last edited: 2013-09-13 22:33:48 +0200 (CEST)
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread Perl mit Kommandozeilenprogramm kommunizieren (Windows)