/[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.12 by joko, Mon Jun 23 19:43:19 2003 UTC revision 1.13 by joko, Mon Jun 23 20:58:31 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ---------------------------------------------------------------------------  ## ---------------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.13  2003/06/23 20:58:31  joko
6    ##  restructured, hopefully makes Linux and Windows (and *BSD) more compatible...  what about IPC::Cmd???
7    ##
8  ##  Revision 1.12  2003/06/23 19:43:19  joko  ##  Revision 1.12  2003/06/23 19:43:19  joko
9  ##  minor cleanup  ##  minor cleanup
10  ##  now using IPC::Session::NoShell  ##  now using IPC::Session::NoShell
# Line 67  use POSIX qw( strftime ); Line 70  use POSIX qw( strftime );
70  use IPC::Run qw( start pump finish timeout run ) ;  use IPC::Run qw( start pump finish timeout run ) ;
71  use Carp;  use Carp;
72    
73  # NEW - 2003-06-23  # NEW - 2003-06-23 for Linux (what about *BSD?)
74  use IPC::Session::NoShell;  use IPC::Session;
75    
76    
77  # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;  # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
# Line 95  sub get_executable { Line 98  sub get_executable {
98    # => better use absolute path-names only?!    # => better use absolute path-names only?!
99    my $application = '';    my $application = '';
100    if ($cmd =~ m/\w+\.pl\s*.*/) {    if ($cmd =~ m/\w+\.pl\s*.*/) {
101      # NEW 2003-06-23 - needed if used with IPC::Session (at Linux)        $application = get_interpreter_wrapper($cmd, 'perl');
102      #  whats about Win32?        #$cmd = "$application $cmd" if $application;
103      $application = 'perl ';        $application .= ' ';
104        
105    } else {    } else {
106      $application = './';      $application = './';
107    }    }
108    return $application;    return $application;
109  }  }
110    
111  sub get_executable_wrapper {  sub get_interpreter_wrapper {
112    my $cmd = shift;    my $cmd = shift;
113    my $application = '';    my $language = shift;
114    # Required to adapt to IPC::Run on win32.    $language ||= '';
115    #if (RUNNING_IN_HELL()) {  
116      #$application = 'cmd.exe /C';    my $wrapper = '';
117    #}  
118    return $application;    if ($language eq 'perl') {
119      
120        if (RUNNING_IN_HELL()) {
121          # Required to adapt to IPC::Run on win32.
122          $wrapper = 'cmd.exe /C perl';
123        } else {
124          # NEW 2003-06-23 - needed if used with IPC::Session (at Linux)
125          #  whats about Win32?
126          $wrapper = 'perl';
127        }
128        
129      } else {
130        die("No wrapper for language '$language'.");
131      }
132      
133      return $wrapper;
134  }  }
135    
136    
# Line 175  sub run_cmd { Line 194  sub run_cmd {
194    # V3 - using IPC (optional)    # V3 - using IPC (optional)
195    if ($options->{async}) {    if ($options->{async}) {
196    
     #$cmd = "$application $cmd" if $application;  
     #my $application = get_executable_wrapper($cmd);  
       
     print STDERR "run_cmd: IPC::Session::NoShell: $cmd", "\n";  
197      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";      #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?";
           
198      my @cmd = split(' ', $cmd);      my @cmd = split(' ', $cmd);
199            
200            
201      # V3.1 - using IPC::Run      # V3.1 - using IPC::Run
202      #      #
203      # tests:      # tests:
204      #my $in; my $out; my $err;      
205      #print "IPC::Run: $cmd", "\n";      if (RUNNING_IN_HELL()) {
206      #start \@cmd, timeout(0) or croak("run_cmd: IPC::Run could not start '$cmd'.");      
207      #        #my $in; my $out; my $err;
208      # success on Win32, but seems broken at 'timeout' on linux:        print STDERR "run_cmd: IPC::Run: $cmd", "\n";
209      #run(\@cmd, timeout(2)) or croak("run_cmd: IPC::Run could not start '$cmd'.");        
210                  # no success!
211      # other tests ;)        #start \@cmd, timeout(0) or croak("run_cmd: IPC::Run could not start '$cmd'.");
212      #$IPC::Run::Timer::timeout = 2000;        #
213      #start $cmd or die("IPC::Run could not start '$cmd'.");        # success on Win32, but seems broken at 'timeout' on linux:
214          run(\@cmd, timeout(4)) or croak("run_cmd: IPC::Run could not start '$cmd'.");
215              
216      # V3.2 - using IPC::Session        # other tests ;)
217      #  success on Linux AND Win32 ??        #$IPC::Run::Timer::timeout = 2000;
218      #        #start $cmd or die("IPC::Run could not start '$cmd'.");
219      # set timeout:        
220      #  (don't really know why we needs 2 secconds      } else {
221      #   to wait for init of process !?!)  
222      my $session_timeout = 2;        print STDERR "run_cmd: IPC::Session: $cmd", "\n";
223      # set session name (default: cmd as string):  
224      my $session_command = $cmd;        # V3.2 - using IPC::Session
225      # create session:        #  success on Linux AND Win32 ??
226      my $session = new IPC::Session::NoShell($session_command, $session_timeout);        #
227              # set timeout:
228      # send 'cmd' to session - not required since complete command is sent via constructor above        #  (don't really know why we needs 2 secconds
229      #$session->send(\@cmd);        #   to wait for init of process !?!)
230              my $session_timeout = 3;
231      # optional switch case:        # set session name (default: cmd as string):
232      #for ($session->stdout()) {        my $session_name = $cmd;
233      #}        # create session:
234      # optional get error:        my $session = IPC::Session->new($session_name, $session_timeout);
235      #my $err = session->stderr();        
236          # send 'cmd' to session - not required since complete command is sent via constructor above
237          $session->send(\@cmd);
238          
239          #print $session->stdout(), "\n";
240          
241          # optional switch case:
242          #for ($session->stdout()) {
243          #}
244          # optional get error:
245          #my $err = session->stderr();
246        }
247            
248    } else {    } else {
249      print STDERR "run_cmd: system('$cmd').", "\n";      print STDERR "run_cmd: system('$cmd').", "\n";

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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