5 sub every_exec (stream|s) {
6 my ($self, $remotes, $options, @command) = @_;
10 $_->ensure(command_service => 'Tak::CommandService') for @$remotes;
12 foreach my $remote (@$remotes) {
13 if ($options->{stream}) {
14 my $stdout = $self->stdout;
15 my $host = $remote->host;
16 push @requests, $remote->start(
18 on_result => sub { $self->print_exec_result($remote, @_) },
20 $stdout->print($host.' '.$_[0].': '.$_[1]);
21 $stdout->print("\n") unless $_[1] =~ /\n\Z/;
24 command_service => stream_exec => \@command
27 push @requests, $remote->start(
28 { on_result => sub { $self->print_exec_result($remote, @_) } },
29 command_service => exec => \@command
33 Tak->await_all(@requests);
36 sub print_exec_result {
37 my ($self, $remote, $result) = @_;
39 my $res = eval { $result->get }
41 $self->stderr->print("Host ${\$remote->host}: Error: $@\n");
45 my $code = $res->{exit_code};
47 "Host ${\$remote->host}: ".($code ? "NOT OK ${code}" : "OK")."\n"
50 $self->stdout->print("Stderr:\n${\$res->{stderr}}\n");
53 $self->stdout->print("Stdout:\n${\$res->{stdout}}\n");