ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ppm
ppm
Capturing PPM output
by Paula J Capacio other posts by this author
Oct 25 2007 7:10AM messages near this date
view in the new Beta List Site
REQUIRE statements for name='perl' | Re: Capturing PPM output
Hello, I am writing a script to execute ppm commands to install modules.
The script works but I am not getting all of the output from the
install.  Specifically, when I use ppm from a command line I get:
C:\Documents and Settings\username> ppm install Bit-Vector
Unpacking Bit-Vector-6.4...done
Unpacking Carp-Clan-5.8...done
Generating HTML for Bit-Vector-6.4...done
Generating HTML for Carp-Clan-5.8...done
Updating files in site area...done
  16 files installed
When I execute the script I get only:
Installing module Bit-Vector
	  16 files installed
The bare minimum script is below. Note I am capturing the output of the
command into an array and attempting to capture any STDERR output.  What
am I doing wrong or is there some other file handle I need to intercept?
Thanks in advance,
Paula 
---script follows (watch out for line wrapping) -----
use strict;
my $rc = 0;
my $fileName = 'PPM_InsMods';
my $modName = 'Bit-Vector';

#redirect STDERR - save the stream so we can it back later
open(TEMPERR, "> \&STDERR");
#redirect it to file
open(STDERR, "> $fileName.err") or die "Cant open file for redirected
STDERR";

print "Installing module $modName\n";
my $command = "ppm install $modName";      # install this module
my @system_out = `$command`;
if ($? != 0) {
      print "\tfailed: $?\n";
      $rc = 4;
}

# Perl HATES when STDIN, STDOUT, and STDERR are closed explicitly
#   (don't do it), set it back to original
open(STDERR, "> \&TEMPERR");
#an error file is always created whether errors exist or not
if ((-s "$fileName.err") == 0) {  #if the size of the file is 0KB then
delete it
      unlink "$fileName.err";
}else{
      print "STDERR from run:\n";
      open(MYERRS, "<$fileName.err") or die "Cant open the .ERR file";
      while (<MYERRS> ) {
            print "\t$_\n";
      }
      close(MYERRS);
}

foreach my $system_out (@system_out)  {
    chomp $system_out;
    print "\t$system_out\n";              #write each line of system
output
}

exit ($rc);

---end of script  
Thread:
Paula J Capacio
Mathieu Longtin

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved