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