I have been attempting to follow the suggestions given in option 3 of the first answer to this similar question. I have succeeded in using the provided commands to redirect input, but I can't manage to redirect output. Here's my commands:
# gdb debugee.exe
(gdb) b main
(gdb) run
(gdb) p dup2(open("output.txt", 256), 1)
(gdb) c
Noticed that I am using 256 to say "create if not exist" and 1 instead of 0 to redirect stdout instead of stdin.
The file is created, and the program output appears to go somewhere, since it doesn't appear in the terminal window; but the file remains empty.
What am I doing wrong? Or are there additional considerations for output?