Answer the question
In order to leave comments, you need to log in
How to capture console output from a C program?
Hello everyone, there is a small console program written in C.
While running, it displays information about its work in the terminal.
How can I redirect this output to a file?
For some reason, the standard Linux methods don't dump anything into the file. At the end of the work, the file is empty.
./app > output.txt
./app > tee -a output.txt
Answer the question
In order to leave comments, you need to log in
Several options are possible:
1. The application writes to stderr, then
./app 2>stderr.txt
2. The application writes to stdout but does not read anything from stdin
by default, the output of fprintf is buffered and the buffer is only flushed when the buffer is full, waiting for input, or exiting the program. You can either turn off buffering
setvbuf(stdout, NULL, _IONBF, 0);
somewhere at the beginning of the program, or force the buffer to be flushed fflush(stdout);
after each printf.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question