2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.17 2003/07/02 11:17:32 jonen |
6 |
|
## minor changes |
7 |
|
## |
8 |
|
## Revision 1.16 2003/06/25 22:49:56 joko |
9 |
|
## RUNNING_IN_HELL mode for detach option |
10 |
|
## |
11 |
|
## Revision 1.15 2003/06/24 20:21:12 jonen |
12 |
|
## + changed linux part of run_cmd to use Proc::Background instead of IPC::... |
13 |
|
## |
14 |
## Revision 1.14 2003/06/24 20:13:18 joko |
## Revision 1.14 2003/06/24 20:13:18 joko |
15 |
## + sub findpatch |
## + sub findpatch |
16 |
## + now using findpatch and Proc::Background for win32/perl |
## + now using findpatch and Proc::Background for win32/perl |
218 |
$cmd = "$application$cmd" if $application; |
$cmd = "$application$cmd" if $application; |
219 |
#} |
#} |
220 |
|
|
221 |
|
my @cmd = split(' ', $cmd); |
222 |
|
|
223 |
# V3 - using IPC (optional) |
# V3 - using IPC (optional) |
224 |
if ($options->{async}) { |
if ($options->{async}) { |
225 |
|
|
226 |
#run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?"; |
#run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?"; |
227 |
my @cmd = split(' ', $cmd); |
|
228 |
|
print STDOUT "run_cmd[async]: Proc::Background: $cmd", "\n"; |
229 |
|
|
230 |
# V3.1 - using IPC::Run |
# V3.1 - using IPC::Run |
231 |
# |
# |
234 |
if (RUNNING_IN_HELL()) { |
if (RUNNING_IN_HELL()) { |
235 |
|
|
236 |
#my $in; my $out; my $err; |
#my $in; my $out; my $err; |
|
print STDOUT "run_cmd: IPC::Run: $cmd", "\n"; |
|
237 |
|
|
238 |
#print STDOUT "findpath: ", findpath('rap.pl'), "\n"; |
#print STDOUT "findpath: ", findpath('rap.pl'), "\n"; |
239 |
|
|
265 |
|
|
266 |
} else { |
} else { |
267 |
|
|
268 |
print STDOUT "run_cmd: IPC::Session: $cmd", "\n"; |
#print STDOUT "run_cmd: IPC::Session: $cmd", "\n"; |
269 |
|
|
270 |
# V3.2 - using IPC::Session |
# V3.2 - using IPC::Session |
271 |
# success on Linux AND Win32 ?? |
# success on Linux AND Win32 ?? |
272 |
# |
# |
273 |
# set timeout: |
# set timeout: |
274 |
# (don't really know why we needs 2 secconds |
# (don't really know why we needs some secconds |
275 |
# to wait for init of process !?!) |
# to wait for init of process !?!) |
276 |
my $session_timeout = 3; |
#my $session_timeout = 15; |
277 |
# set session name (default: cmd as string): |
# set session name (default: cmd as string): |
278 |
my $session_name = $cmd; |
#my $session_command = $cmd; |
279 |
# create session: |
#my $session_shell = "/bin/sh"; |
280 |
my $session = IPC::Session->new($session_name, $session_timeout); |
# create session (beware of using '->new' here!?): |
281 |
|
#my $session = new IPC::Session($session_shell, $session_timeout); |
282 |
|
|
283 |
# send 'cmd' to session - not required since complete command is sent via constructor above |
# send 'cmd' to session - not required since complete command is sent via constructor above |
284 |
$session->send(\@cmd); |
#$session->send($cmd); |
285 |
|
|
286 |
#print $session->stdout(), "\n"; |
#my $output = $session->stdout(); |
287 |
|
#print "WS::Admin started.\n" if $output = ' '; |
288 |
|
|
289 |
|
# tests |
290 |
|
#$session->send("echo hello"); |
291 |
|
#chomp(my $hello = $session->stdout()); |
292 |
|
#print "ok 3\n" if $hello eq "hello"; |
293 |
|
|
294 |
# optional switch case: |
# optional switch case: |
295 |
#for ($session->stdout()) { |
#for ($session->stdout()) { |
296 |
|
# /_bootDataBases/ && do { print "WS::Admin started.\n" }; |
297 |
#} |
#} |
298 |
# optional get error: |
# optional get error: |
299 |
#my $err = session->stderr(); |
#my $err = session->stderr(); |
300 |
|
#print "ERR: " . Dumper($err) . "\n"; |
301 |
|
|
302 |
|
#open( *OUT, ">out.txt" ) ; |
303 |
|
#open( *ERR, ">err.txt" ) ; |
304 |
|
#run(\@cmd, \undef, \*OUT, \*ERR ) or croak("run_cmd: IPC::Run could not start '$cmd'."); |
305 |
|
#my ($out, $err); |
306 |
|
#my $h = start(\@cmd, \undef, \*OUT, \*ERR ) or croak("run_cmd: IPC::Run could not start '$cmd'."); |
307 |
|
#finish $h if $err =~ /error/; |
308 |
|
|
309 |
|
# get child pid |
310 |
|
#my $kid; |
311 |
|
#do { $kid=wait(); } until $kid > 0; |
312 |
|
#print "Child PID: " . $kid . "n"; |
313 |
|
|
314 |
|
#finish $h; |
315 |
|
|
316 |
|
|
317 |
|
# test using Proc::Background - success !! |
318 |
|
my $proc = Proc::Background->new($cmd); |
319 |
|
my $kid = $proc->pid(); |
320 |
|
print STDOUT "run_cmd: Proc::Background: $cmd, child PID $kid", "\n"; |
321 |
|
$proc->wait(); |
322 |
|
$proc->die(); |
323 |
|
|
324 |
} |
} |
325 |
|
|
326 |
|
|
327 |
|
} elsif ($options->{detach}) { |
328 |
|
|
329 |
|
if (RUNNING_IN_HELL()) { |
330 |
|
print STDOUT "run_cmd[detach]: Proc::Background: $cmd", "\n"; |
331 |
|
my $proc1 = Proc::Background->new(@cmd); |
332 |
|
print "pid: ", $proc1->pid(), "\n"; |
333 |
|
} else { |
334 |
|
print STDOUT "run_cmd[detach]: system('$cmd' &).", "\n"; |
335 |
|
system($cmd . ' &'); |
336 |
|
} |
337 |
|
|
338 |
} else { |
} else { |
339 |
print STDOUT "run_cmd: system('$cmd').", "\n"; |
print STDOUT "run_cmd: system('$cmd').", "\n"; |
340 |
system($cmd); |
system($cmd); |