Hi POE
I would like to get an error_level for each program i run in parallel...
And it would also be nice to get a value back so i can track which program
that return a
given answer...
Thanks a lot in advance...
Michael , Denmark.
----------------- snip -------------------
#!/usr/bin/perl
use warnings;
use strict;
use POE;
use POE::Wheel::Run;
my $time1=time();
# Start a multitasking session to manage several child processes. Map
# each event to a function which will handle it. Run POE::Kernel,
# which manages the session's activity. run() will return when the
# session is done, and so we exit.
POE::Session->new
( _start => \&start_processes,
process_stdout => \&read_stdout,
process_stderr => \&read_stderr,
process_closed => \&cleanup_proc_wheel,
);
POE::Kernel->run();
my $time2=time();
my $usedtime=$time2-$time1;
print"$time2 - $time1 - $usedtime\n";
exit 0;
# Start a number of child processes. Record their abstractions
# (wheels) in the session's local storage (its "heap"). All the
# process events include the IDs of the wheels that have activity.
# We'll use that later to clean up after finished processes.
sub start_processes {
my $session_storage = $_[HEAP];
my $nr;
my @servers;
my $t;
my $command="uptime";
$nr = @servers = qw(xxx.xxx.xxx.xxx);
for (1..1) {
for ($t=0;$t<$nr;$t++) {
my $program="ssh $servers[$t] $command";
my $proc_wheel = POE::Wheel::Run->new
( Program => "$program",
StdoutEvent => "process_stdout",
StderrEvent => "process_stderr",
CloseEvent => "process_closed",
);
$session_storage->{$proc_wheel->ID} = $proc_wheel;
}
}
}
# Process stdout and stderr from the child process.
sub read_stdout {
my ($stdout, $proc_wheel_id) = @_[ARG0, ARG1];
print "Wheel $proc_wheel_id stdout: $stdout\n";
}
sub read_stderr {
my ($stderr, $proc_wheel_id) = @_[ARG0, ARG1];
print "Wheel $proc_wheel_id stderr: $stderr\n";
}
# Clean up after a process when it's done.
sub cleanup_proc_wheel {
my ($session_storage, $proc_wheel_id) = @_[HEAP, ARG0];
delete $session_storage->{$proc_wheel_id};
}