/[cvs]/nfo/perl/libs/shortcuts.pm
ViewVC logotype

Diff of /nfo/perl/libs/shortcuts.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by joko, Tue Jun 24 20:13:18 2003 UTC revision 1.19 by joko, Tue May 11 19:45:30 2004 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ---------------------------------------------------------------------------  ## ---------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.19  2004/05/11 19:45:30  joko
6    ##  now exporting RUNNING_IN_HELL
7    ##
8    ##  Revision 1.18  2003/12/05 04:58:04  joko
9    ##  + minor update: doesn't require IPC::Session anymore
10    ##
11    ##  Revision 1.17  2003/07/02 11:17:32  jonen
12    ##  minor changes
13    ##
14    ##  Revision 1.16  2003/06/25 22:49:56  joko
15    ##  RUNNING_IN_HELL mode for detach option
16    ##
17    ##  Revision 1.15  2003/06/24 20:21:12  jonen
18    ##  + changed linux part of run_cmd to use Proc::Background instead of IPC::...
19    ##
20  ##  Revision 1.14  2003/06/24 20:13:18  joko  ##  Revision 1.14  2003/06/24 20:13:18  joko
21  ##  + sub findpatch  ##  + sub findpatch
22  ##  + now using findpatch and Proc::Background for win32/perl  ##  + now using findpatch and Proc::Background for win32/perl
# Line 65  our @EXPORT_OK = qw( Line 80  our @EXPORT_OK = qw(
80    get_chomped    get_chomped
81    bool2status    bool2status
82    make_guid    make_guid
83      RUNNING_IN_HELL
84  );  );
85    
86    
# Line 75  use IPC::Run qw( start pump finish timeo Line 91  use IPC::Run qw( start pump finish timeo
91  use Carp;  use Carp;
92    
93  # NEW - 2003-06-23 for Linux (what about *BSD?)  # NEW - 2003-06-23 for Linux (what about *BSD?)
94  use IPC::Session;  #use IPC::Session;
95    
96  use File::Spec;  use File::Spec;
97  use Proc::Background;  use Proc::Background;
# Line 209  sub run_cmd { Line 225  sub run_cmd {
225      $cmd = "$application$cmd" if $application;      $cmd = "$application$cmd" if $application;
226    #}    #}
227    
228      my @cmd = split(' ', $cmd);
229    
230    # V3 - using IPC (optional)    # V3 - using IPC (optional)
231    if ($options->{async}) {    if ($options->{async}) {
232    
233      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";
234      my @cmd = split(' ', $cmd);  
235            print STDOUT "run_cmd[async]: Proc::Background: $cmd", "\n";
236            
237      # V3.1 - using IPC::Run      # V3.1 - using IPC::Run
238      #      #
# Line 223  sub run_cmd { Line 241  sub run_cmd {
241      if (RUNNING_IN_HELL()) {      if (RUNNING_IN_HELL()) {
242            
243        #my $in; my $out; my $err;        #my $in; my $out; my $err;
       print STDOUT "run_cmd: IPC::Run: $cmd", "\n";  
244                
245        #print STDOUT "findpath: ", findpath('rap.pl'), "\n";        #print STDOUT "findpath: ", findpath('rap.pl'), "\n";
246                
# Line 255  sub run_cmd { Line 272  sub run_cmd {
272                
273      } else {      } else {
274    
275        print STDOUT "run_cmd: IPC::Session: $cmd", "\n";        #print STDOUT "run_cmd: IPC::Session: $cmd", "\n";
276    
277        # V3.2 - using IPC::Session        # V3.2 - using IPC::Session
278        #  success on Linux AND Win32 ??        #  success on Linux AND Win32 ??
279        #        #
280        # set timeout:        # set timeout:
281        #  (don't really know why we needs 2 secconds        #  (don't really know why we needs some secconds
282        #   to wait for init of process !?!)        #   to wait for init of process !?!)
283        my $session_timeout = 3;        #my $session_timeout = 15;
284        # set session name (default: cmd as string):        # set session name (default: cmd as string):
285        my $session_name = $cmd;        #my $session_command = $cmd;
286        # create session:        #my $session_shell = "/bin/sh";
287        my $session = IPC::Session->new($session_name, $session_timeout);        # create session (beware of using '->new' here!?):
288          #my $session = new IPC::Session($session_shell, $session_timeout);
289                
290        # 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
291        $session->send(\@cmd);        #$session->send($cmd);
292          
293        #print $session->stdout(), "\n";        #my $output = $session->stdout();
294          #print "WS::Admin started.\n" if $output = ' ';
295    
296          # tests
297          #$session->send("echo hello");
298          #chomp(my $hello = $session->stdout());      
299          #print "ok 3\n" if $hello eq "hello";
300                
301        # optional switch case:        # optional switch case:
302        #for ($session->stdout()) {        #for ($session->stdout()) {
303          #  /_bootDataBases/ && do { print "WS::Admin started.\n" };
304        #}        #}
305        # optional get error:        # optional get error:
306        #my $err = session->stderr();        #my $err = session->stderr();
307          #print "ERR: " . Dumper($err) . "\n";
308    
309          #open( *OUT, ">out.txt" ) ;
310          #open( *ERR, ">err.txt" ) ;
311          #run(\@cmd, \undef,  \*OUT, \*ERR  ) or croak("run_cmd: IPC::Run could not start '$cmd'.");
312          #my ($out, $err);
313          #my $h = start(\@cmd, \undef,  \*OUT, \*ERR  ) or croak("run_cmd: IPC::Run could not start '$cmd'.");
314          #finish $h if $err =~ /error/;
315          
316          # get child pid
317          #my $kid;
318          #do { $kid=wait(); } until $kid > 0;
319          #print "Child PID: " . $kid . "n";
320    
321          #finish $h;
322    
323          
324          # test using Proc::Background - success !!
325          my $proc = Proc::Background->new($cmd);
326          my $kid = $proc->pid();
327          print STDOUT "run_cmd: Proc::Background: $cmd, child PID $kid", "\n";
328          $proc->wait();
329          $proc->die();
330    
331      }      }
332        
333    
334      } elsif ($options->{detach}) {
335    
336        if (RUNNING_IN_HELL()) {
337          print STDOUT "run_cmd[detach]: Proc::Background: $cmd", "\n";
338          my $proc1 = Proc::Background->new(@cmd);
339          print "pid: ", $proc1->pid(), "\n";
340        } else {
341          print STDOUT "run_cmd[detach]: system('$cmd' &).", "\n";
342          system($cmd . ' &');    
343        }
344    
345    } else {    } else {
346      print STDOUT "run_cmd: system('$cmd').", "\n";      print STDOUT "run_cmd: system('$cmd').", "\n";
347        #print $ENV{PERL5LIB}, "\n";
348      system($cmd);      system($cmd);
349    }    }
350        

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.19

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed