How to capture output of CVS via Perl?

Discussion in 'Perl Misc' started by Chris Weiss, Oct 8, 2004.

  1. Chris Weiss

    Chris Weiss Guest

    I'm trying to capture the output of a cvs update session to a log file
    using ActivePerl and can't seem to get it captured - the CVS results
    still dump to the screen and not to a file...

    Here's the snippit of code I'm trying:

    open(STDOUT, ">".$logfile);
    system($cvs." ".$cvsroot." ".$cvs_update_args);

    Any thoughts on what's going on? Does ActivePerl not support SDTOUT?

    Any help would be greatly appreciated!
    Chris Weiss, Oct 8, 2004
    #1
    1. Advertising

  2. Chris Weiss

    John Bokma Guest

    (Chris Weiss) wrote in news:653ab165.0410081329.168fb685
    @posting.google.com:

    > I'm trying to capture the output of a cvs update session to a log file
    > using ActivePerl and can't seem to get it captured - the CVS results
    > still dump to the screen and not to a file...
    >
    > Here's the snippit of code I'm trying:
    >
    > open(STDOUT, ">".$logfile);
    > system($cvs." ".$cvsroot." ".$cvs_update_args);


    perldoc -f system

    also, you don't need that weird . stuff, you know Perl can perfectly
    interpolate strings?

    "$cvs $cvsroot $cvs_update_args"

    > Any thoughts on what's going on? Does ActivePerl not support SDTOUT?


    Sure it does.

    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Oct 8, 2004
    #2
    1. Advertising

  3. Chris Weiss <> wrote:


    > open(STDOUT, ">".$logfile);


    > Any help would be greatly appreciated!



    You should always, yes *always*, test the return value from open():

    open(STDOUT, ">$logfile") or die "could not open '$logfile' $!";


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Oct 9, 2004
    #3
  4. Chris Weiss

    Paul Lalli Guest

    Chris Weiss wrote:
    > I'm trying to capture the output of a cvs update session to a log file
    > using ActivePerl and can't seem to get it captured - the CVS results
    > still dump to the screen and not to a file...
    >
    > Here's the snippit of code I'm trying:
    >
    > open(STDOUT, ">".$logfile);


    Always check the return value of open.

    > system($cvs." ".$cvsroot." ".$cvs_update_args);


    You're not even bothering to determine if this command ran successfully.

    > Any thoughts on what's going on?


    Yes. You have a misperception about the cvs command.

    > Does ActivePerl not support SDTOUT?


    I've never heard of any language supporting SDTOUT. STDOUT, on the
    other hand...

    > Any help would be greatly appreciated!


    Forget perl for a moment. Try this command in your shell:

    cvs update > output.txt 2> err.txt

    The results of that should point you in the right direction.

    Paul Lalli
    Paul Lalli, Oct 9, 2004
    #4
  5. Chris Weiss

    Ben Morrow Guest

    Quoth (Chris Weiss):
    > I'm trying to capture the output of a cvs update session to a log file
    > using ActivePerl and can't seem to get it captured - the CVS results
    > still dump to the screen and not to a file...
    >
    > Here's the snippit of code I'm trying:
    >
    > open(STDOUT, ">".$logfile);
    > system($cvs." ".$cvsroot." ".$cvs_update_args);


    Under Win2k or later

    system "$cvs $cvsroot $cvs_update_args > $logfile 2>&1";

    Under earlier windows versions the only thing I've ever found to work is
    mucking about with Win32::process, which is Highly Unpleasant.

    Ben

    --
    perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
    qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
    1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
    2047502190/' #
    Ben Morrow, Oct 9, 2004
    #5
  6. Chris Weiss

    Chris Weiss Guest

    Paul Lalli <> wrote in message news:<ck79n2$j7l$>...
    > Chris Weiss wrote:
    > > I'm trying to capture the output of a cvs update session to a log file
    > > using ActivePerl and can't seem to get it captured - the CVS results
    > > still dump to the screen and not to a file...
    > >
    > > Here's the snippit of code I'm trying:
    > >
    > > open(STDOUT, ">".$logfile);

    >
    > Always check the return value of open.
    >


    Will do - this was a first stab.

    > > system($cvs." ".$cvsroot." ".$cvs_update_args);

    >
    > You're not even bothering to determine if this command ran successfully.


    That's the intent of capturing the output. To parse for errors (of all
    kinds) and send the log via email (that part I have working with other
    portions of the script).

    >
    > > Any thoughts on what's going on?

    >
    > Yes. You have a misperception about the cvs command.


    Feel free to enlighten - I should have started with "I'm new to
    this...", but it seems pretty obvious.

    >
    > > Does ActivePerl not support SDTOUT?

    >
    > I've never heard of any language supporting SDTOUT. STDOUT, on the
    > other hand...


    I'm also a horrible typist.

    >
    > > Any help would be greatly appreciated!

    >
    > Forget perl for a moment. Try this command in your shell:
    >
    > cvs update > output.txt 2> err.txt
    >
    > The results of that should point you in the right direction.
    >
    > Paul Lalli


    Sorry about the duplicate posts - The google post form timed out and
    I'd assumed it did so before completing the operation.
    Chris Weiss, Oct 9, 2004
    #6
  7. Chris Weiss

    Paul Lalli Guest

    Chris Weiss wrote:

    > Paul Lalli <> wrote in message news:<ck79n2$j7l$>...
    >
    >>Chris Weiss wrote:
    >>
    >>>system($cvs." ".$cvsroot." ".$cvs_update_args);

    >>
    >>You're not even bothering to determine if this command ran successfully.

    >
    > That's the intent of capturing the output. To parse for errors (of all
    > kinds) and send the log via email (that part I have working with other
    > portions of the script).


    Capturing output is not a particular good means of determining *if*
    there was an error - only to determine what the error was. All programs
    return an exit code that tells you whether or not the program succeeded
    or failed. Read the documentation for the function you're using:

    perldoc -f system


    >>>Any thoughts on what's going on?

    >>
    >>Yes. You have a misperception about the cvs command.

    >
    > Feel free to enlighten - I should have started with "I'm new to
    > this...", but it seems pretty obvious.


    Did you try the program I told you to below? That should tell you your
    misperception.

    >>>Any help would be greatly appreciated!

    >>
    >>Forget perl for a moment. Try this command in your shell:
    >>
    >>cvs update > output.txt 2> err.txt


    Paul Lalli
    Paul Lalli, Oct 9, 2004
    #7
  8. Chris Weiss <> wrote:
    > Paul Lalli <> wrote in message news:<ck79n2$j7l$>...
    >> Chris Weiss wrote:


    >> > open(STDOUT, ">".$logfile);

    >>
    >> Always check the return value of open.

    >
    > Will do - this was a first stab.



    Checking the return value from open() is best employed as a first stab. :)


    >> > system($cvs." ".$cvsroot." ".$cvs_update_args);

    >>
    >> You're not even bothering to determine if this command ran successfully.

    >
    > That's the intent of capturing the output.



    You seem to be confusing errors with output.

    The return value from system() indicates errors (if it is a "polite" program).

    The output from system() is NOT captured at all, you need a different
    operator to capture the output.


    > To parse for errors (of all
    > kinds) and send the log via email (that part I have working with other
    > portions of the script).



    Then you want to be capturing STDERR, as that is where the error
    messages should be going.

    perldoc -q STDERR

    How can I capture STDERR from an external command?


    >> You have a misperception about the cvs command.

    >
    > Feel free to enlighten - I should have started with "I'm new to
    > this...", but it seems pretty obvious.



    We might assume you are new to Perl, but we would not assume that
    you are new to programming itself...


    >> Forget perl for a moment. Try this command in your shell:
    >>
    >> cvs update > output.txt 2> err.txt
    >>
    >> The results of that should point you in the right direction.



    The enlightenment offered here is:

    program's normal output goes to STDOUT

    program's error output goes to STDERR


    Which one you want to capture depends on which one you want to capture. :)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Oct 9, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ddog
    Replies:
    3
    Views:
    576
    Jason Whaley
    Aug 4, 2007
  2. Replies:
    1
    Views:
    583
    GArlington
    Aug 31, 2007
  3. David Ross
    Replies:
    5
    Views:
    141
    Nicholas Van Weerdenburg
    Dec 5, 2004
  4. Holger Biebinger

    CVS access via PERL

    Holger Biebinger, Apr 19, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    298
    Holger Biebinger
    Apr 20, 2004
  5. Chris Weiss

    How to capture output of CVS via Perl?

    Chris Weiss, Oct 8, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    91
    John Bokma
    Oct 8, 2004
Loading...

Share This Page