--- nfo/perl/libs/shortcuts.pm 2003/06/23 15:59:16 1.10 +++ nfo/perl/libs/shortcuts.pm 2003/06/23 17:41:50 1.11 @@ -1,7 +1,10 @@ ## --------------------------------------------------------------------------- -## $Id: shortcuts.pm,v 1.10 2003/06/23 15:59:16 joko Exp $ +## $Id: shortcuts.pm,v 1.11 2003/06/23 17:41:50 jonen Exp $ ## --------------------------------------------------------------------------- ## $Log: shortcuts.pm,v $ +## Revision 1.11 2003/06/23 17:41:50 jonen +## + NEW - used IPC::Session instead of IPC::Run to get better results at linux +## ## Revision 1.10 2003/06/23 15:59:16 joko ## major/minor fixes? ## @@ -60,6 +63,8 @@ use IPC::Run qw( start pump finish timeout run ) ; use Carp; +# NEW - 2003-06-23 +use IPC::Session; # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; @@ -83,6 +88,8 @@ # => better use absolute path-names only?! my $application = ''; if ($cmd =~ m/\w+\.pl\s*.*/) { + # NEW 2003-06-23 - needed if used with IPC::Session (at Linux) + # whats about Win32? $application = 'perl '; } else { $application = './'; @@ -94,10 +101,9 @@ my $cmd = shift; my $application = ''; # Required to adapt to IPC::Run on win32. - if (RUNNING_IN_HELL()) { + #if (RUNNING_IN_HELL()) { #$application = 'cmd.exe /C'; - $application = 'cmd.exe /C'; - } + #} return $application; } @@ -162,23 +168,52 @@ $cmd = "$application$cmd" if $application; } - # V3 - using IPC::Run (optional) + # V3 - using IPC (optional) if ($options->{async}) { - my $application = get_executable_wrapper($cmd); - $cmd = "$application $cmd" if $application; + + #$cmd = "$application $cmd" if $application; + #my $application = get_executable_wrapper($cmd); print "run_cmd: IPC::Run: $cmd", "\n"; #run \@cmd, \$in, \$out, \$err, timeout( 10 ) or die "cat: $?"; - + my @cmd = split(' ', $cmd); - my $in; my $out; my $err; + + # V3.1 - using IPC::Run + # + # tests: + #my $in; my $out; my $err; #print "IPC::Run: $cmd", "\n"; #start \@cmd, timeout(0) or croak("run_cmd: IPC::Run could not start '$cmd'."); - run(\@cmd, timeout(2)) or croak("run_cmd: IPC::Run could not start '$cmd'."); - + # + # success on Win32, but seems broken at 'timeout' on linux: + #run(\@cmd, timeout(2)) or croak("run_cmd: IPC::Run could not start '$cmd'."); + + # other tests ;) #$IPC::Run::Timer::timeout = 2000; #start $cmd or die("IPC::Run could not start '$cmd'."); + + + # V3.2 - using IPC::Session + # success on Linux AND Win32 ?? + # + # set timeout: + # (don't really know why we needs 2 secconds + # to wait for init of process !?!) + my $session_timeout = 2; + # set session name (default: cmd as string): + my $session_name = $cmd; + # create session: + my $session = new IPC::Session($session_name, $session_timeout); + # send 'cmd' to session: + $session->send(\@cmd); + # optional switch case: + #for ($session->stdout()) { + #} + # optional get error: + #my $err = session->stderr(); + } else { print "run_cmd: system('$cmd').", "\n"; @@ -240,4 +275,6 @@ return $guid; } + + 1;