diff --git a/lib/PBot/Plugin/RunCommand.pm b/lib/PBot/Plugin/RunCommand.pm index b0604a98..96cae45e 100644 --- a/lib/PBot/Plugin/RunCommand.pm +++ b/lib/PBot/Plugin/RunCommand.pm @@ -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; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index bc4ebbcf..eba46b58 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -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", };