line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl
|
2
|
|
|
|
|
|
|
#
|
3
|
|
|
|
|
|
|
# The copyright notice and plain old documentation (POD)
|
4
|
|
|
|
|
|
|
# are at the end of this file.
|
5
|
|
|
|
|
|
|
#
|
6
|
|
|
|
|
|
|
package Proc::Command;
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1067
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
9
|
1
|
|
|
1
|
|
26
|
use 5.001;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings::register;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
139
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#####
|
15
|
|
|
|
|
|
|
# Connect up with the event log.
|
16
|
|
|
|
|
|
|
#
|
17
|
1
|
|
|
1
|
|
6
|
use vars qw( $VERSION $DATE $FILE);
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
99
|
|
18
|
|
|
|
|
|
|
$VERSION = '1.05';
|
19
|
|
|
|
|
|
|
$DATE = '2003/07/27';
|
20
|
|
|
|
|
|
|
$FILE = __FILE__;
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA @EXPORT_OK);
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
336
|
|
23
|
|
|
|
|
|
|
require Exporter;
|
24
|
|
|
|
|
|
|
@ISA=('Exporter');
|
25
|
|
|
|
|
|
|
@EXPORT_OK = qw(&command);
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
######
|
28
|
|
|
|
|
|
|
# backtick that does not use the shell for Perl under Windows
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
#
|
31
|
|
|
|
|
|
|
sub command
|
32
|
|
|
|
|
|
|
{
|
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
33
|
1
|
0
|
66
|
shift @_ if $_[0] eq 'Proc::Command' || ref($_[0]); # drop self on object call
|
35
|
1
|
|
|
|
|
2
|
my ($command, $trys, $sleep) = @_;
|
36
|
|
|
|
|
|
|
|
37
|
1
|
50
|
|
|
|
4
|
$trys = 1 unless $trys;
|
38
|
1
|
50
|
|
|
|
4
|
$sleep = 2 unless $sleep;
|
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
2
|
my ($i, @response);
|
41
|
1
|
|
|
|
|
3
|
for( $i=0; $i<$trys; $i++ ) {
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#######
|
44
|
|
|
|
|
|
|
# This form does not use the shell to execute the command.
|
45
|
|
|
|
|
|
|
#
|
46
|
|
|
|
|
|
|
# Having the shell pop-up in middle of a long run, just ... bad.
|
47
|
|
|
|
|
|
|
#
|
48
|
1
|
50
|
|
|
|
3
|
$command = "MCR $command" if $^O eq 'VMS';
|
49
|
1
|
50
|
|
|
|
7216
|
unless (open (CMD, '-|', $command)) {
|
50
|
0
|
0
|
|
|
|
0
|
unless( $i < $trys ) {
|
51
|
0
|
|
|
|
|
0
|
warn "Cannot fork $command\n";
|
52
|
0
|
|
|
|
|
0
|
return undef;
|
53
|
|
|
|
|
|
|
}
|
54
|
0
|
0
|
|
|
|
0
|
last unless $i < $trys;
|
55
|
0
|
|
|
|
|
0
|
sleep( $sleep );
|
56
|
0
|
|
|
|
|
0
|
next;
|
57
|
|
|
|
|
|
|
}
|
58
|
1
|
|
|
|
|
9581
|
@response = ;
|
59
|
1
|
50
|
|
|
|
109
|
unless( close CMD ) {
|
60
|
0
|
0
|
|
|
|
0
|
unless( $i < $trys ) {
|
61
|
0
|
|
|
|
|
0
|
warn "Error $? forking $command\n";
|
62
|
0
|
|
|
|
|
0
|
return undef;
|
63
|
|
|
|
|
|
|
}
|
64
|
0
|
|
|
|
|
0
|
sleep( $sleep );
|
65
|
0
|
|
|
|
|
0
|
next;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
}
|
69
|
1
|
50
|
|
|
|
16
|
@response = () unless @response;
|
70
|
1
|
50
|
|
|
|
59
|
return wantarray ? @response : (join '',@response);
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__
|