How to capture output of CVS via Perl?

C

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);

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

Any help would be greatly appreciated!
 
J

John Bokma

(e-mail address removed) (Chris Weiss) wrote in @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.
 
P

Paul Lalli

Chris said:
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
 
B

Ben Morrow

Quoth (e-mail address 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::process, which is Highly Unpleasant.

Ben
 
C

Chris Weiss

Paul Lalli said:
Always check the return value of open.

Will do - this was a first stab.
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).
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.
I've never heard of any language supporting SDTOUT. STDOUT, on the
other hand...

I'm also a horrible typist.
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.
 
P

Paul Lalli

Chris said:
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

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.

Paul Lalli
 
T

Tad McClellan

Chris Weiss said:
Will do - this was a first stab.


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

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?

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...



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. :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top