--- nfo/perl/libs/shortcuts.pm 2003/06/24 20:13:18 1.14 +++ nfo/perl/libs/shortcuts.pm 2003/06/24 20:21:12 1.15 @@ -1,7 +1,10 @@ ## --------------------------------------------------------------------------- -## $Id: shortcuts.pm,v 1.14 2003/06/24 20:13:18 joko Exp $ +## $Id: shortcuts.pm,v 1.15 2003/06/24 20:21:12 jonen Exp $ ## --------------------------------------------------------------------------- ## $Log: shortcuts.pm,v $ +## Revision 1.15 2003/06/24 20:21:12 jonen +## + changed linux part of run_cmd to use Proc::Background instead of IPC::... +## ## Revision 1.14 2003/06/24 20:13:18 joko ## + sub findpatch ## + now using findpatch and Proc::Background for win32/perl @@ -255,32 +258,69 @@ } else { - print STDOUT "run_cmd: IPC::Session: $cmd", "\n"; + #print STDOUT "run_cmd: IPC::Session: $cmd", "\n"; # V3.2 - using IPC::Session # success on Linux AND Win32 ?? # # set timeout: - # (don't really know why we needs 2 secconds + # (don't really know why we needs some secconds # to wait for init of process !?!) - my $session_timeout = 3; + #my $session_timeout = 15; # set session name (default: cmd as string): - my $session_name = $cmd; - # create session: - my $session = IPC::Session->new($session_name, $session_timeout); + #my $session_command = $cmd; + #my $session_shell = "/bin/sh"; + # create session (beware of using '->new' here!?): + #my $session = new IPC::Session($session_shell, $session_timeout); # send 'cmd' to session - not required since complete command is sent via constructor above - $session->send(\@cmd); - - #print $session->stdout(), "\n"; + #$session->send($cmd); + + #my $output = $session->stdout(); + #print "WS::Admin started.\n" if $output = ' '; + + # tests + #$session->send("echo hello"); + #chomp(my $hello = $session->stdout()); + #print "ok 3\n" if $hello eq "hello"; # optional switch case: #for ($session->stdout()) { + # /_bootDataBases/ && do { print "WS::Admin started.\n" }; #} # optional get error: #my $err = session->stderr(); + #print "ERR: " . Dumper($err) . "\n"; + + #open( *OUT, ">out.txt" ) ; + #open( *ERR, ">err.txt" ) ; + #run(\@cmd, \undef, \*OUT, \*ERR ) or croak("run_cmd: IPC::Run could not start '$cmd'."); + #my ($out, $err); + #my $h = start(\@cmd, \undef, \*OUT, \*ERR ) or croak("run_cmd: IPC::Run could not start '$cmd'."); + #finish $h if $err =~ /error/; + + # get child pid + #my $kid; + #do { $kid=wait(); } until $kid > 0; + #print "Child PID: " . $kid . "n"; + + #finish $h; + + + # test using Proc::Background - success !! + my $proc = Proc::Background->new($cmd); + my $kid = $proc->pid(); + print STDOUT "run_cmd: Proc::Background: $cmd, child PID $kid", "\n"; + $proc->wait(); + $proc->die(); + } - + + + } elsif ($options->{detach}) { + print STDERR "run_cmd: system('$cmd' &).", "\n"; + system($cmd . ' &'); + } else { print STDOUT "run_cmd: system('$cmd').", "\n"; system($cmd);