There are two scripts.
script2.pl is called from script1.pl
Both scripts write to same file 'xyz.log'. script2.pl opens with append mode.
Script1.pl
----------
#!/usr/local/bin/perl
$logFl = "xyz.log";
open (FIRSTFH, "> $logFl") || die "couldn't open file...$!\n";
print FIRSTFH "This is from first script\n";
system("script2.pl $logFl");
#print FIRSTFH "This is second print in first script\n";
Script2.pl
----------
#!/usr/local/bin/perl
$logFl2 = "xyz.log";
open (FIRSTFH, ">> $logFl2") || die "couldn't open file in script2...$
+!\n";
print FIRSTFH "This is from second script\n";
Running above script1.pl will result with following file.
$ cat xyz.log
This is from first script
This is from second script
But if commented line
#print FIRSTFH "This is second print in first script\n";
is uncommented and ran then following will be the result.
$ cat xyz.log
This is from first script
This is second print in first script
Please let me know how to make script1.pl work so that all messages are in order in output file. That is it should contain three messages
This is from first script
This is from second script
This is second print in first script
Thanks
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.