-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrc-capture
executable file
·60 lines (41 loc) · 1.74 KB
/
rc-capture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/local/bin/perl
## capture the command-line, stdout and stderr
# 2022-11-16 still trying to reliably remove 'Potential difficulties' warnings...
# 2020-02-25 kludge for 'unhandled Failure detected in DESTROY' flapper [now obsolete]
# 2020-01-15 maybe that JIT thing is fixed? Let's see...
# 2018-10-02 filter out out 'JIT ERROR' [now obsolete]
# default temp file names
$prefix = '/tmp/rc-capture.std';
$out = "$prefix.out.$$";
$err = "$prefix.err.$$";
# usage
exec "pod2text $0" unless @ARGV;
if ($#ARGV == 0 && $ARGV[0] =~ /[\s>]/) {
($cmd,$args,$out) = $ARGV[0] =~ /(\S+)\s*(.*)?>+\s*(.*)/;
} else {
$args = join ' ', @ARGV;
}
system "$cmd $args > $out 2> $err";
print "::CMD::\n$cmd $args\n\n";
print "::STDOUT::\n" . `cat $out` . "\n" unless -z $out;
print "::STDERR::\n" . `cat $err` . "\n" if -s $err and not `cat $err` =~ /Potential difficulties/ms;
# above line deals with spurious warnings from Clifford and Math::Matrix:
# F/Fibonacci_matrix-exponentiation
# O/Orbital_elements
# P/Polynomial_regression
unlink $out, $err;
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=head1 NAME
rc-capture - capture command-line, stdout and stderr
=head1 SYNOPSIS
rc-capture B<command> [ B<args> ]
=head1 DESCRIPTION
Captures the command-line, stdout and stderr, then present them on STDOUT,
in that order. The three sections of output are marked with the lines:
::CMD:: ::STDOUT:: ::STDERR::
If the 'command' being executed needs to redirect it's own STDOUT
you must quote the entire command string:
Capture 'find / -type l -print > all_links'
Note that appending (B<E<gt>E<gt>>) with STDOUT will not work.
=head1 AUTHOR
David Hoekman <[email protected]>