/[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.8 by joko, Fri Apr 4 17:31:59 2003 UTC revision 1.9 by joko, Tue May 13 05:36:24 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ---------------------------------------------------------------------------  ## ---------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.9  2003/05/13 05:36:24  joko
6    ##  heavy modifications to run_cmd
7    ##  + sub get_executable
8    ##  + sub get_executable_wrapper
9    ##
10  ##  Revision 1.8  2003/04/04 17:31:59  joko  ##  Revision 1.8  2003/04/04 17:31:59  joko
11  ##  + sub make_guid  ##  + sub make_guid
12  ##  ##
# Line 49  our @EXPORT_OK = qw( Line 54  our @EXPORT_OK = qw(
54  use Data::Dumper;  use Data::Dumper;
55  use POSIX qw( strftime );  use POSIX qw( strftime );
56  #use IPC::Run qw( run timeout );  #use IPC::Run qw( run timeout );
57  use IPC::Run qw( start pump finish timeout ) ;  use IPC::Run qw( start pump finish timeout run ) ;
58  use Carp;  use Carp;
59    
60    
# Line 68  sub today { Line 73  sub today {
73    return strftime("%Y-%m-%d", localtime);    return strftime("%Y-%m-%d", localtime);
74  }  }
75    
76    sub get_executable {
77      my $cmd = shift;
78      # FIXME: detect type of program and run with proper application/interpreter
79      # using IPC::Run we have to dispatch this on our own! *no* os-interaction or interpolation here!?
80      # => better use absolute path-names only?!
81      my $application = '';
82      if ($cmd =~ m/\w+\.pl\s*.*/) {
83        $application = 'perl';
84      }
85      return $application;
86    }
87    
88    sub get_executable_wrapper {
89      my $cmd = shift;
90      my $application = '';
91      # Required to adapt to IPC::Run on win32.
92      if (RUNNING_IN_HELL()) {
93        #$application = 'cmd.exe /C';
94        $application = 'cmd.exe /C';
95      }
96      return $application;
97    }
98    
99    
100  sub run_cmd {  sub run_cmd {
101    my $cmd = shift;    my $cmd = shift;
102    my $caption = shift;    my $caption = shift;
103    my $options = shift;    my $options = shift;
104    #$cmd = 'perl ' . $cmd;    #$cmd = 'perl ' . $cmd;
105        
106      #print Dumper($options);
107      
108    # report - header    # report - header
109    my $sep = "-" x 60;    my $sep = "-" x 60;
110    print $sep, "\n";    print $sep, "\n";
# Line 88  sub run_cmd { Line 119  sub run_cmd {
119    $cmd =~ m/(.+?)\s/;    $cmd =~ m/(.+?)\s/;
120    my $executable = $1;    my $executable = $1;
121        
122    =pod
123    # for unix: check if executable is in local directory, if so - prefix with './'    # for unix: check if executable is in local directory, if so - prefix with './'
124    if (!RUNNING_IN_HELL()) {    if (!RUNNING_IN_HELL()) {
125      #if ($cmd !~ m/\//) {      #if ($cmd !~ m/\//) {
126      if (-e $executable) {      if (-e $executable) {
       $cmd = "./$cmd";  
127      }      }
128    }    }
129      =cut
130    
131      # new of 2003-05-07: basedir option to be prepended to command string
132      my $basedir = $options->{BASEDIR};
133      my $use_path = $options->{USE_PATH};
134    
135      # for all systems: check existance of files - use basedir if given, try current directory otherwise
136      if ($basedir) {
137        -e "$basedir/$executable" or die("$basedir/$executable does not exist.");
138        $basedir .= '/';
139      } elsif ($use_path) {
140        $basedir = "";
141      } else {
142        -e $executable or die("$executable does not exist.");
143        #$basedir = ".";
144        $basedir .= './';
145      }
146      $cmd = "$basedir$cmd";
147    
148    # V1 - backticks or qq{}    # V1 - backticks or qq{}
149    #`$cmd`;    #`$cmd`;
150    #qq{$cmd};    #qq{$cmd};
# Line 105  sub run_cmd { Line 154  sub run_cmd {
154    
155    # V3 - using IPC::Run (optional)    # V3 - using IPC::Run (optional)
156    if ($options->{async}) {    if ($options->{async}) {
157      # FIXME: detect type of program and run with proper application/interpreter      my $application = get_executable_wrapper($cmd);
     # using IPC::Run we have to dispatch this on our own! *no* os-interaction or interpolation here!  
     # => better use absolute path-names only?!  
     my $application = '';  
     if (RUNNING_IN_HELL()) {  
       $application = 'cmd.exe /C';  
     }  
       
     if ($cmd =~ m/\w+\.pl\s*.*/) {  
       $application = 'perl';  
     }  
       
158      $cmd = "$application $cmd" if $application;      $cmd = "$application $cmd" if $application;
159            
160      print "IPC::Run: $cmd", "\n";      print "run_cmd: IPC::Run: $cmd", "\n";
161      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";
162            
163      my @cmd = split(' ', $cmd);      my @cmd = split(' ', $cmd);
164            
165      my $in; my $out; my $err;      my $in; my $out; my $err;
166      start \@cmd, timeout(0) or die("IPC::Run could not start '$cmd'.");      #print "IPC::Run: $cmd", "\n";
167        #start \@cmd, timeout(0) or croak("run_cmd: IPC::Run could not start '$cmd'.");
168        run(\@cmd, timeout(2)) or croak("run_cmd: IPC::Run could not start '$cmd'.");
169            
170      #$IPC::Run::Timer::timeout = 2000;      #$IPC::Run::Timer::timeout = 2000;
171      #start $cmd or die("IPC::Run could not start '$cmd'.");      #start $cmd or die("IPC::Run could not start '$cmd'.");
172            
173    } else {    } else {
174        if (!$use_path) {
175          my $application = get_executable($cmd);
176          $cmd = "$application $cmd" if $application;
177        }
178        print "run_cmd: system('$cmd').", "\n";
179      system($cmd);      system($cmd);
180    }    }
181        
182    print "ready.", "\n";    print "run_cmd: ready.", "\n";
183        
184  }  }
185    
186  sub run_cmds {  sub run_cmds {
187      my $options = {};
188      if (ref $_[$#_] eq 'HASH') {
189        #print "YAI", "\n";
190        $options = pop @_;
191      }
192    foreach (@_) {    foreach (@_) {
193      run_cmd($_);      run_cmd($_, '', $options);
194    }    }
195  }  }
196    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

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