Browse Source

bin/filter-exec*: grab stderr so it doesn't wind up atop files

This is already handled in filter-exec-stdin, using IPC::Cmd, which may
be what I should do here, but I guess this is ok.
main
Brennen Bearnes 3 months ago
parent
commit
8d5717aea4
3 changed files with 20 additions and 7 deletions
  1. +5
    -1
      home/bin/filter-exec
  2. +14
    -6
      home/bin/filter-exec-raw
  3. +1
    -0
      home/bin/filter-exec-stdin

+ 5
- 1
home/bin/filter-exec View File

@ -35,7 +35,11 @@ sub handle_block {
die "bogus cmd";
}
my $result = `$cmd`;
# Note that we're redirecting stderr here, so it shows up inside the
# output block rather than at the top of the filtered file:
my $result = qx{$cmd 2>&1};
# Indent output by four lines, mostly for the benefit of markdown documents:
$result =~ s/^/ /gm;
return "$startmarker\n\n \$ " . $cmd . "\n" . $result . "\n$endmarker";


+ 14
- 6
home/bin/filter-exec-raw View File

@ -45,7 +45,11 @@ print $text;
sub handle_block {
my ($start, $command, $command_end, $end) = @_;
my $result = `$command`;
# Note that we're redirecting stderr here, so it shows up inside the
# output block rather than at the top of the filtered file:
my $result = qx{$command 2>&1};
return "${start}exec-raw ${command}${command_end}\n${result}${end}";
}
@ -53,20 +57,24 @@ __DATA__
A self-test - use ,r in vim to check:
{{{exec-raw date
Thu 02 Apr 2020 11:49:22 AM MDT
Fri 18 Jun 2021 04:40:02 PM MDT
}}}
<!-- exec-raw date -->
Thu 02 Apr 2020 11:49:22 AM MDT
Fri 18 Jun 2021 04:40:02 PM MDT
<!-- end -->
<!-- exec-raw pwd -->
/home/brennen/notes
/home/brennen/code/bpb-kit
<!-- end -->
<!-- exec -->
$ ls ~/bin/filter-exec-raw
/home/brennen/bin/filter-exec-raw
$ ls -lah ~/bin/filter-exec-raw
-rwxr-xr-x 1 brennen brennen 1.5K Jun 18 16:38 /home/brennen/bin/filter-exec-raw
<!-- end -->
{{{exec-raw ls adfasdfsf
ls: cannot access 'adfasdfsf': No such file or directory
}}}

+ 1
- 0
home/bin/filter-exec-stdin View File

@ -57,6 +57,7 @@ A self-test - add some numbers and use ,r in vim to check:
<!-- exec-stdin sort -n -->
1
2
3
8
9
10


Loading…
Cancel
Save