This ought to be easier, but under some versions of Win32 DOS, this snippet proves useful.

The scenario: You want to go ahead and upgrade those modules you've installed via Active State PPM, for which PPM finds newer versions available while searching using the 'ppm upgrade' command. On one of my systems, I have dozens of modules installed, and at any given time, six or seven of them may benefit from being updated. If I type ppm upgrade to find the list of modules that have upgrades, two things happen. First, a long list of every module I have installed via PPM gets spewed to the screen (most say XXX::YYYY: up to date, while some list upgrades available), and second, the list goes scrolling right off the screen.

The quickest solution would be ppm upgrade > upgrade.txt, to redirect the output. But alas, that simply doesn't work on some versions of MSDOS for Win32. Why? Who knows. At first I thought maybe the report was going to STDERR or something, but no, it just won't redirect. The output file is created, but it just remains empty.

What follows is a quick one-liner solution for people who want only the list of modules that do need updating, and need the list dumped to a file where they can read it without worrying about it scrolling into oblivion.

This one liner still uses redirection, but fortunately, this way it actually works, and has the added bonus of allowing Perl to toss out the unneeded list of modules that don't need updating.

perl -e "print qq/$_\n/ for grep( ! /up to date/, split( /\n/, `ppm up +grade` ) )" > update.txt

Replies are listed 'Best First'.
Re: Redirect filtered PPM screen output to a file.
by tye (Sage) on Sep 20, 2004 at 05:23 UTC

    qx returns a list of lines when in a list context:

    perl -e "print for grep ! /up to date/, `ppm upgrade`" > update.txt

    - tye        

      Thanks tye. I should have re-read perlop, since it is so seldom that I use the qx// (and backticks) operators.

      While we're at it, print prints lists too. ;)

      perl -e "print grep ! /up to date/, `ppm upgrade`" > update.txt


      Dave

Re: Redirect filtered PPM screen output to a file.
by ambrus (Abbot) on Sep 20, 2004 at 18:23 UTC

    In dos you can redirect all of std{in,out,err} by creating a batch file like

    @echo off stty update.txt ppm update stty con
    I understand that ppm update does not simply write to stderr, but you could still try if this works.

    (This is the only way to redirect error messages to nul in dos as command does not have a redirect operator to redirect stderr.)