I have two programs. The first program creates a log file, same as display of the terminal. So I am using the below code in unix terminal, for get the log file creation. And it’s working fine.

# first.pl open (STDOUT, "| tee -a $LOGFILE") or die "Teeing off: $!\n";

At the end of the program I call the second program (`perl second.pl $LOGFILE`) and I wish to get the user entered inputs only in $LOGFILE. ( No need to captured the terminal display). I am using the LOG file handler to append the user entered inputs. But I am getting the terminal display also. How to avid the terminal display in the log file.

Thanks,
Mani Muthu


Hi Monks

I got the solution. Below I place the sample code for that one.

The first file : I wish to captured the screen display in log file

# parent.pl # Preserve the filehandler open(OLDOUT, ">&STDOUT"); $LOGFILE="output.txt"; open LOG_FH, ">>$LOGFILE" ; # disable perl buffering so that when you log messages on the screen t +o the logfile , select LOG_FH; $| = 1; select STDOUT; $| = 1; # Open STDOUT to log messages to file ... open (STDOUT, "| tee -a $LOGFILE") or die "Teeing off: $!\n"; print "\nEnter Parent Process Input : "; $p_input1=<>; chomp ($p_input1); print LOG_FH "\nYou Entered : $p_input1"; close (LOG_FH); close (STDOUT); ## redirect the file handler open(STDOUT, ">&OLDOUT"); ## No need the screen output to the log file system("perl child.pl $LOGFILE");

The second file : I wish to user entered inputs only in the log file

# child.pl $LOGFILE=$ARGV[0]; open FOUT, ">>$LOGFILE" ; print "\nEnter the child process input : "; $c_input1=<STDIN>; print FOUT "\nYou Entered Child Input : $c_input1"; close (FOUT);

In reply to Terminal Display - Log File Creation by k_manimuthu

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.