/[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.5 by joko, Sat Feb 22 17:26:13 2003 UTC revision 1.7 by joko, Sat Mar 29 07:24:10 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ---------------------------------------------------------------------------  ## ---------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.7  2003/03/29 07:24:10  joko
6    ##  enhanced 'run_cmd': now tries to execute program with appropriate application (e.g. 'cmd.exe' or 'perl')
7    ##
8    ##  Revision 1.6  2003/03/28 06:58:06  joko
9    ##  new: 'run_cmd' now asynchronous! (via IPC::Run...)
10    ##
11  ##  Revision 1.5  2003/02/22 17:26:13  joko  ##  Revision 1.5  2003/02/22 17:26:13  joko
12  ##  + enhanced unix compatibility fix  ##  + enhanced unix compatibility fix
13  ##  ##
# Line 39  our @EXPORT_OK = qw( Line 45  our @EXPORT_OK = qw(
45  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main
46    
47  use Data::Dumper;  use Data::Dumper;
48  use POSIX qw(strftime);  use POSIX qw( strftime );
49    #use IPC::Run qw( run timeout );
50    use IPC::Run qw( start pump finish timeout ) ;
51    
52  # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;  # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
53  # see "perldoc -f localtime"  # see "perldoc -f localtime"
# Line 59  sub today { Line 67  sub today {
67  sub run_cmd {  sub run_cmd {
68    my $cmd = shift;    my $cmd = shift;
69    my $caption = shift;    my $caption = shift;
70      my $options = shift;
71    #$cmd = 'perl ' . $cmd;    #$cmd = 'perl ' . $cmd;
72      
73      # report - header
74    my $sep = "-" x 60;    my $sep = "-" x 60;
75    print $sep, "\n";    print $sep, "\n";
76    print "  ", $cmd, "\n";    #print "  ", $cmd, "\n";
77    print "  ", $caption, "\n" if $caption;    #print "  ", "  $caption", "\n" if $caption;
78      print "  ", $cmd;
79      print " - ", $caption if $caption;
80      print "\n";
81    print $sep, "\n";    print $sep, "\n";
82        
83    # strip name of executable from full command string    # strip name of executable from full command string
# Line 78  sub run_cmd { Line 92  sub run_cmd {
92      }      }
93    }    }
94        
95    system($cmd);    # V1 - backticks or qq{}
96    #`$cmd`;    #`$cmd`;
97      #qq{$cmd};
98      
99      # V2 - via 'system'
100      #system($cmd);
101    
102      # V3 - using IPC::Run (optional)
103      if ($options->{async}) {
104        # FIXME: detect type of program and run with proper application/interpreter
105        # using IPC::Run we have to dispatch this on our own! *no* os-interaction or interpolation here!
106        # => better use absolute path-names only?!
107        my $application = '';
108        if (RUNNING_IN_HELL()) {
109          $application = 'cmd.exe /C';
110        }
111        
112        if ($cmd =~ m/\w+\.pl\s*.*/) {
113          $application = 'perl';
114        }
115        
116        $cmd = "$application $cmd" if $application;
117        
118        print "IPC::Run: $cmd", "\n";
119        #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";
120        
121        my @cmd = split(' ', $cmd);
122        
123        my $in; my $out; my $err;
124        start \@cmd, timeout(0) or die("IPC::Run could not start '$cmd'.");
125        
126        #$IPC::Run::Timer::timeout = 2000;
127        #start $cmd or die("IPC::Run could not start '$cmd'.");
128        
129      } else {
130        system($cmd);
131      }
132      
133    print "ready.", "\n";    print "ready.", "\n";
134      
135  }  }
136    
137  sub run_cmds {  sub run_cmds {

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.7

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