mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-18 06:20:41 +01:00
pbot-vm: improve exit-code handling
This commit is contained in:
parent
164ecc45a7
commit
3e2204a6b0
@ -441,8 +441,6 @@ sub cmd_print_last_statement($context, $args) {
|
||||
}
|
||||
|
||||
sub handle_program_exit($context, $data) {
|
||||
my $reason = $data->{reason};
|
||||
|
||||
if (not -s OUTPUT_FILENAME) { # -s gets size of file
|
||||
my $locals = locals_to_string($context->{locals_end});
|
||||
|
||||
@ -451,6 +449,10 @@ sub handle_program_exit($context, $data) {
|
||||
}
|
||||
}
|
||||
|
||||
if (exists $data->{'exit-code'} && $data->{'exit-code'} != 0) {
|
||||
$context->{'exit-code'} = oct $data->{'exit-code'};
|
||||
}
|
||||
|
||||
_exit($context);
|
||||
}
|
||||
|
||||
@ -541,7 +543,7 @@ sub handle_exec_async_output($context, $output) {
|
||||
if ($reason eq 'breakpoint-hit') {
|
||||
handle_breakpoint_hit($context, $output);
|
||||
}
|
||||
elsif ($reason eq 'exited-normally') {
|
||||
elsif ($reason eq 'exited-normally' || $reason eq 'exited') {
|
||||
handle_program_exit($context, $output);
|
||||
}
|
||||
elsif ($reason eq 'signal-received') {
|
||||
@ -592,9 +594,9 @@ sub _exit($context) {
|
||||
my $output = do { local $/; <$fh> };
|
||||
close $fh;
|
||||
|
||||
print STDOUT "$output\n";
|
||||
print STDOUT "$output";
|
||||
|
||||
exit;
|
||||
exit ($context->{'exit-code'} // 0);
|
||||
}
|
||||
|
||||
# send text to OUTPUT_FILENAME file
|
||||
|
@ -150,9 +150,11 @@ sub run_command($command, $mod) {
|
||||
if (not $mod->{error}) {
|
||||
$mod->{output} .= "Success (no output).\n";
|
||||
} else {
|
||||
$mod->{output} .= "Exit code $mod->{error}.\n";
|
||||
$mod->{output} .= "Exit $mod->{error}.\n";
|
||||
}
|
||||
}
|
||||
} elsif ($mod->{error}) {
|
||||
$mod->{output} .= " [Exit $mod->{error}]";
|
||||
}
|
||||
|
||||
return $mod->{output};
|
||||
|
@ -68,7 +68,7 @@ sub postprocess {
|
||||
$self->SUPER::postprocess;
|
||||
|
||||
# no errors compiling, but if output contains something, it must be diagnostic messages
|
||||
if(length $self->{output}) {
|
||||
if (length $self->{output}) {
|
||||
$self->{output} =~ s/^\s+//;
|
||||
$self->{output} =~ s/\s+$//;
|
||||
$self->{output} = "[$self->{output}]\n";
|
||||
@ -97,6 +97,8 @@ sub postprocess {
|
||||
($exitval, $stdout, $stderr) = $self->execute(60, $input, '/bin/sh');
|
||||
}
|
||||
|
||||
$self->{error} = $exitval;
|
||||
|
||||
my $result = $stderr;
|
||||
$result .= ' ' if length $result;
|
||||
$result .= $stdout;
|
||||
|
Loading…
x
Reference in New Issue
Block a user