Thread system Aufruf mit Perl in Array speichern (12 answers)
Opened by krusty at 2007-01-12 10:59

bloonix
 2007-01-12 17:59
#73146 #73146
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hier mal ein simples Beispiel mit CPAN:IPC::Open3

Code: (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
#!/usr/bin/perl -wT
use strict;
use IPC::Open3;

$ENV{PATH} = '/sbin';

my ($wtr, $rdr, $err, $ret);
my $pid = open3($wtr, $rdr, $err, 'ifconfig', '-abc');
close $wtr;
waitpid $pid, 0;
$ret = $? / 256;

if ($ret == 0) {
  while (my $line = <$rdr>) {
     print $line; # oder deine Verarbeitung
  }
} else {
  local $/;
  my $errors = $err ? <$err> : <$rdr>;
  print STDERR "Unable to execute ifconfig: ($ret)\n";
  print STDERR "$errors" if $errors;
}

close $rdr;
close $err if $err;

exit $ret;


#> ./test.pl
Unable to execute ifconfig: (1)
ifconfig: option `-abc' not recognised.
ifconfig: `--help' gives usage information.
\n\n

<!--EDIT|opi|1168618864-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread system Aufruf mit Perl in Array speichern