I have two script files: program1.pl and program2.pl.

I would like the execution output to be recorded in a text file: output.txt.

What I have done is in program2.pl:

$filename = "output.txt"; system("perl /absolute/path/to/program1> $filename");
Then add progam2.pl to cron job list. The next morning I will be able to read output.txt.

What's in program1.pl:

... print "Start xxx job..."; # some code to do the job print "End of doing xxx job.";
Notice that I didn't define the output stream in program1.pl, so by default it goes to STDOUT.

I have no problem finding the two print statements in my output file: output.txt. But when I do the following, I started getting problems:

(program1.pl) $projectSourceDir ='/absolute/path'; chdir $projectSourceDir; print "Do cvs update ...\n"; open INFO, "cvs update -dP |"; my @cvsInfo = <INFO>; close INFO; my $cvsInfo= join("", @cvsInfo); print "$cvsInfo"; print "done\n\n";
What I want to do is perform a "cvs update" on a project's source code and then do something with the updated source code. I want to record the cvs update information, i.e. what file has been changed, what not, etc.. But if I do it in the way listed above, I sometimes get the CVS update in output.txt, most of the time I don't, although I am sure that source files are changed.

Thanks ahead.


In reply to output to a file by sachaer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.