Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] stdout redirection



  Hector Akamine asked:

> If I want to redirect the output to files, it is just matter of doing
> something like
> $myprog 1>log_stdout.txt 2>log_stderr.txt
> 
> However I have the following problems:
> 
> 1) In the case the program does not return (i.e., waiting for a
> message or something, need to use Ctrl-C to terminate it),
> log_stdout.txt is empty (however log_stderr.txt correctly has the
> redirected stderr messages).  This is weird for me because if I just
> $myprog 2>log_stderr.txt
> stdout messages are shown in the console. Is this behavior normal? Is
> it possible to change this?
> 

    I don't know exactly what's going "wrong" here, but it sounds
to me like a problem with flushing (the buffer, that is). You may 
want to look at the fflush() function. 


> 2) How can I do in order to show the messages both in the console and
> also to save those in a file?

    Check out the "tee" command:

For example:
   ./myprog | tee desired.outputFile.name

This will dump the output from myprog to stdout as well as to the
file named desired.outputFile.name

   -Chris


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links