Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to capture output of CVS via Perl?

Reply
Thread Tools

How to capture output of CVS via Perl?

 
 
Chris Weiss
Guest
Posts: n/a
 
      10-08-2004
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!
 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      10-08-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      10-08-2004
Chris Weiss <(E-Mail Removed)> 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
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      10-09-2004
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
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      10-09-2004

Quoth (E-Mail Removed) (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:rocess, 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/' # (E-Mail Removed)
 
Reply With Quote
 
Chris Weiss
Guest
Posts: n/a
 
      10-09-2004
Paul Lalli <(E-Mail Removed)> wrote in message news:<ck79n2$j7l$(E-Mail Removed)>...
> 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.
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      10-09-2004
Chris Weiss wrote:

> Paul Lalli <(E-Mail Removed)> wrote in message news:<ck79n2$j7l$(E-Mail Removed)>...
>
>>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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-09-2004
Chris Weiss <(E-Mail Removed)> wrote:
> Paul Lalli <(E-Mail Removed)> wrote in message news:<ck79n2$j7l$(E-Mail Removed)>...
>> 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
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Eclipse and CVS, Eclipse wipes out CVS directories xyzzy12@hotmail.com Java 1 08-31-2007 10:19 AM
Eclipse 3.2 and CVS - where and how to get and install CVS? ddog Java 3 08-04-2007 06:41 PM
[ANN] Ruby CVS IRC bot, and Ruby CVS RSS feed David Ross Ruby 5 12-05-2004 03:48 AM
How to capture output of CVS via Perl? Chris Weiss Perl Misc 1 10-08-2004 10:57 PM



Advertisments