Pavel
Pavel

Reputation: 277

How I can capture all output of my application?

I'm writing a C++ application and I want to capture all application output (asserts, exceptions, segfaults) into text file and console at the same time. How can I do that?

Upvotes: 0

Views: 123

Answers (2)

Kristd
Kristd

Reputation: 11

use the dup2 function to redirect the stdout_fileno, example:

fd = open(filename, O_CREAT|O_APPEND|O_WRONLY, 0755);
close(STDOUT_FILENO);
dup2(fd, STDOUT_FILENO);

Upvotes: 1

Mureinik
Mureinik

Reputation: 311163

You could use the tee command:

$ /path/to/myapp 2>&1 | tee /path/to/file.log

Upvotes: 2

Related Questions