2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.7 2003/03/29 07:24:10 joko |
6 |
|
## enhanced 'run_cmd': now tries to execute program with appropriate application (e.g. 'cmd.exe' or 'perl') |
7 |
|
## |
8 |
|
## Revision 1.6 2003/03/28 06:58:06 joko |
9 |
|
## new: 'run_cmd' now asynchronous! (via IPC::Run...) |
10 |
|
## |
11 |
|
## Revision 1.5 2003/02/22 17:26:13 joko |
12 |
|
## + enhanced unix compatibility fix |
13 |
|
## |
14 |
|
## Revision 1.4 2003/02/22 17:19:36 joko |
15 |
|
## + unix compatibility fix |
16 |
|
## |
17 |
## Revision 1.3 2003/02/14 14:17:04 joko |
## Revision 1.3 2003/02/14 14:17:04 joko |
18 |
## - shortened seperator |
## - shortened seperator |
19 |
## |
## |
45 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
46 |
|
|
47 |
use Data::Dumper; |
use Data::Dumper; |
48 |
use POSIX qw(strftime); |
use POSIX qw( strftime ); |
49 |
|
#use IPC::Run qw( run timeout ); |
50 |
|
use IPC::Run qw( start pump finish timeout ) ; |
51 |
|
|
52 |
# $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; |
# $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; |
53 |
# see "perldoc -f localtime" |
# see "perldoc -f localtime" |
67 |
sub run_cmd { |
sub run_cmd { |
68 |
my $cmd = shift; |
my $cmd = shift; |
69 |
my $caption = shift; |
my $caption = shift; |
70 |
|
my $options = shift; |
71 |
#$cmd = 'perl ' . $cmd; |
#$cmd = 'perl ' . $cmd; |
72 |
|
|
73 |
|
# report - header |
74 |
my $sep = "-" x 60; |
my $sep = "-" x 60; |
75 |
print $sep, "\n"; |
print $sep, "\n"; |
76 |
print " ", $cmd, "\n"; |
#print " ", $cmd, "\n"; |
77 |
print " ", $caption, "\n" if $caption; |
#print " ", " $caption", "\n" if $caption; |
78 |
|
print " ", $cmd; |
79 |
|
print " - ", $caption if $caption; |
80 |
|
print "\n"; |
81 |
print $sep, "\n"; |
print $sep, "\n"; |
82 |
system($cmd); |
|
83 |
|
# strip name of executable from full command string |
84 |
|
$cmd =~ m/(.+?)\s/; |
85 |
|
my $executable = $1; |
86 |
|
|
87 |
|
# for unix: check if executable is in local directory, if so - prefix with './' |
88 |
|
if (!RUNNING_IN_HELL()) { |
89 |
|
#if ($cmd !~ m/\//) { |
90 |
|
if (-e $executable) { |
91 |
|
$cmd = "./$cmd"; |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
|
# V1 - backticks or qq{} |
96 |
#`$cmd`; |
#`$cmd`; |
97 |
|
#qq{$cmd}; |
98 |
|
|
99 |
|
# V2 - via 'system' |
100 |
|
#system($cmd); |
101 |
|
|
102 |
|
# V3 - using IPC::Run (optional) |
103 |
|
if ($options->{async}) { |
104 |
|
# FIXME: detect type of program and run with proper application/interpreter |
105 |
|
# using IPC::Run we have to dispatch this on our own! *no* os-interaction or interpolation here! |
106 |
|
# => better use absolute path-names only?! |
107 |
|
my $application = ''; |
108 |
|
if (RUNNING_IN_HELL()) { |
109 |
|
$application = 'cmd.exe /C'; |
110 |
|
} |
111 |
|
|
112 |
|
if ($cmd =~ m/\w+\.pl\s*.*/) { |
113 |
|
$application = 'perl'; |
114 |
|
} |
115 |
|
|
116 |
|
$cmd = "$application $cmd" if $application; |
117 |
|
|
118 |
|
print "IPC::Run: $cmd", "\n"; |
119 |
|
#run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?"; |
120 |
|
|
121 |
|
my @cmd = split(' ', $cmd); |
122 |
|
|
123 |
|
my $in; my $out; my $err; |
124 |
|
start \@cmd, timeout(0) or die("IPC::Run could not start '$cmd'."); |
125 |
|
|
126 |
|
#$IPC::Run::Timer::timeout = 2000; |
127 |
|
#start $cmd or die("IPC::Run could not start '$cmd'."); |
128 |
|
|
129 |
|
} else { |
130 |
|
system($cmd); |
131 |
|
} |
132 |
|
|
133 |
print "ready.", "\n"; |
print "ready.", "\n"; |
134 |
|
|
135 |
} |
} |
136 |
|
|
137 |
sub run_cmds { |
sub run_cmds { |
151 |
return ($bool ? 'ok' : 'failed'); |
return ($bool ? 'ok' : 'failed'); |
152 |
} |
} |
153 |
|
|
154 |
|
sub RUNNING_IN_HELL () { $^O eq 'MSWin32' } |
155 |
|
|
156 |
|
|
157 |
1; |
1; |