-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCapture
executable file
·53 lines (35 loc) · 1.28 KB
/
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
#!/usr/local/bin/perl
## capture the command-line, stdout and stderr
# David H. 2000-08-24
# default temp file names
$prefix = '/tmp/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" unless -z $err;
unlink $out if $out =~ m#$prefix#;
unlink $err;
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=head1 NAME
Capture - capture command-line, stdout and stderr
=head1 SYNOPSIS
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]>