mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-05 19:49:32 +01:00
Plugin/RunCommand: output STDERR lines; output error if command not found
This commit is contained in:
parent
03a14c4928
commit
7aac2bba50
@ -50,27 +50,43 @@ sub cmd_runcmd {
|
||||
|
||||
my ($in, $out, $err);
|
||||
|
||||
my $h = start \@args, \$in, \$out, \$err;
|
||||
my $h = eval { start \@args, \$in, \$out, \$err };
|
||||
|
||||
if ($@) {
|
||||
return "Error starting command: $@";
|
||||
}
|
||||
|
||||
my $lines = 0;
|
||||
|
||||
while (pump $h) {
|
||||
$lines += $self->send_lines($context, \$out);
|
||||
$lines += $self->send_lines($context, \$err);
|
||||
}
|
||||
|
||||
finish $h;
|
||||
|
||||
$lines += $self->send_lines($context, \$out);
|
||||
$lines += $self->send_lines($context, \$out, 1);
|
||||
$lines += $self->send_lines($context, \$err, 1);
|
||||
|
||||
return "No output." if not $lines;
|
||||
}
|
||||
|
||||
sub send_lines {
|
||||
my ($self, $context, $buffer) = @_;
|
||||
my ($self, $context, $buffer, $send_all) = @_;
|
||||
|
||||
my $lines = 0;
|
||||
|
||||
while ($$buffer =~ s/(.{1,370})//) {
|
||||
my $regex;
|
||||
|
||||
if ($send_all) {
|
||||
# all lines
|
||||
$regex = qr/(.{1,450})/;
|
||||
} else {
|
||||
# lines that end with a newline
|
||||
$regex = qr/^(.{1,450})\s+/;
|
||||
}
|
||||
|
||||
while ($$buffer =~ s/$regex//) {
|
||||
my $line = $1;
|
||||
$line =~ s/^\s+|\s+$//g;
|
||||
|
||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4342,
|
||||
BUILD_REVISION => 4343,
|
||||
BUILD_DATE => "2021-08-04",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user