Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Terminal Display - Log File Creation

by k_manimuthu (Monk)
on Sep 02, 2010 at 10:09 UTC ( #858534=perlquestion: print w/replies, xml ) Need Help??
k_manimuthu has asked for the wisdom of the Perl Monks concerning the following question:

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.

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

At the end of the program I call the second program (`perl $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.

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

# # 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 $LOGFILE");

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

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

Replies are listed 'Best First'.
Re: Terminal Display - Log File Creation
by k_manimuthu (Monk) on Sep 06, 2010 at 05:13 UTC
    I got the solution. And the sample code update in this post.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://858534]
Approved by planetscape
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-06-19 20:10 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.