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