[Bio] / FigKernelPackages / FIG.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIG.pm

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

revision 1.387, Thu Oct 27 16:20:34 2005 UTC revision 1.388, Fri Oct 28 16:03:12 2005 UTC
# Line 2522  Line 2522 
2522      (system($cmd) == 0) || Confess("FAILED: $cmd");      (system($cmd) == 0) || Confess("FAILED: $cmd");
2523  }  }
2524    
2525    =head3 run_gathering_output
2526    
2527    C<< FIG::run_gathering_output($cmd, @args); >>
2528    
2529    or
2530    
2531    C<< $fig->run_gathering_output($cmd, @args); >>
2532    
2533    Run a command, gathering the output. This is similar to the backtick
2534    operator, but it does not invoke the shell. Note that the argument list
2535    must be explicitly passed one command line argument per argument to
2536    run_gathering_output.
2537    
2538    If the command fails, the error will be traced.
2539    
2540    =cut
2541    
2542    sub run_gathering_output {
2543        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
2544        my($cmd, @args) = @_;
2545    
2546        #
2547        # Run the command in a safe fork-with-pipe/exec.
2548        #
2549    
2550        my $pid = open(PROC_READ, "-|");
2551    
2552        if ($pid == 0)
2553        {
2554            exec { $cmd } $cmd, @args;
2555            die "could not execute $cmd @args: $!\n";
2556        }
2557    
2558        if (wantarray)
2559        {
2560            my @out;
2561            while (<PROC_READ>)
2562            {
2563                push(@out, $_);
2564            }
2565            if (!close(PROC_READ))
2566            {
2567                Confess("FAILED: $cmd @args with error return $?");
2568            }
2569            return @out;
2570        }
2571        else
2572        {
2573            my $out = '';
2574    
2575            while (<PROC_READ>)
2576            {
2577                $out .= $_;
2578            }
2579            if (!close(PROC_READ))
2580            {
2581                Confess("FAILED: $cmd @args with error return $?");
2582            }
2583            return $out;
2584        }
2585    }
2586    
2587  =head3 augment_path  =head3 augment_path
2588    
2589  C<< FIG::augment_path($dirName); >>  C<< FIG::augment_path($dirName); >>

Legend:
Removed from v.1.387  
changed lines
  Added in v.1.388

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3