stdout and stderr to console and file simultaneously

I

ids

Hi,

Is it possible to display the output of a child program on the console
AND capture it at the same time by redirecting to a file?

Say I have a Makefile and a program that invokes 'gmake' using:

01) system("gmake -f Makefile");

OR

02) system("gmake -f Makefile > build_report.txt");

OR

03) popen("gmake -f Makefile 2>&1", "r");

(01) will write the stdout and stderr of 'gmake' to the console. (02)
allows me to capture the stdout, but it sends only the stderr to the
console. (03) helps to capture both stdout and stderr, but it hides
both from the console.

What I'm looking for is a method to capture both stderr and stdout and
display to the console at the same time. Is there a way to do that?

Thanks,
ids.
 
K

Kenny McCormack

What I'm looking for is a method to capture both stderr and stdout and
display to the console at the same time. Is there a way to do that?

man tee[/QUOTE]

Sea cow!!!
 
C

CBFalconer

ids said:
Great! The following command does the job.

system("gmake -f Makefile 2>&1 | tee build_report.txt");

Anthony gave you an off-topic answer that doesn't apply to many
(most?) systems. It looks as if you are lucky and have a usable
tee program (or shell command).

You should have asked this question on a newsgroup dealing with
your operating system.
 
K

Keith Thompson

CBFalconer said:
Anthony gave you an off-topic answer that doesn't apply to many
(most?) systems. It looks as if you are lucky and have a usable
tee program (or shell command).

You should have asked this question on a newsgroup dealing with
your operating system.

He simply asked a "How do I do this?" question. The fact that
standard C deons't provide a solution doesn't mean that asking it here
was inappropriate. Probably Anthony Fremont, in answering the
question, should have suggested a different newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top