Plugin/RunCommand: output STDERR lines; output error if command not found

This commit is contained in:
Pragmatic Software 2021-08-04 20:03:25 -07:00
parent 03a14c4928
commit 7aac2bba50
2 changed files with 21 additions and 5 deletions

View File

@ -50,27 +50,43 @@ sub cmd_runcmd {
my ($in, $out, $err); 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; my $lines = 0;
while (pump $h) { while (pump $h) {
$lines += $self->send_lines($context, \$out); $lines += $self->send_lines($context, \$out);
$lines += $self->send_lines($context, \$err);
} }
finish $h; 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; return "No output." if not $lines;
} }
sub send_lines { sub send_lines {
my ($self, $context, $buffer) = @_; my ($self, $context, $buffer, $send_all) = @_;
my $lines = 0; 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; my $line = $1;
$line =~ s/^\s+|\s+$//g; $line =~ s/^\s+|\s+$//g;

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script # These are set by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4342, BUILD_REVISION => 4343,
BUILD_DATE => "2021-08-04", BUILD_DATE => "2021-08-04",
}; };