'gdb: Redirect stdout without running the program

In gdb, we normally use r > log.txt to redirect stdout. This also runs the program.

Is there a way to redirect stdout (only, not stdin) without actually starting the program?

My intended workflow is:

redirect stdout to log.txt
call func1(a, b, c) # I want the stdout output going to log.txt, without any gdb info, just stdout

Note that tty command won't work in this case (I want to redirect stdout only).

gdb


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source