Reputation: 277
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
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
Reputation: 311163
You could use the tee
command:
$ /path/to/myapp 2>&1 | tee /path/to/file.log
Upvotes: 2