SRobertJames
SRobertJames

Reputation: 9206

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).

Upvotes: 0

Views: 318

Answers (1)

Employed Russian
Employed Russian

Reputation: 213576

My intended workflow is:

Your intended workflow will not work: you can't call func1(...) without first running the program.

It appears that what you want is (roughly):

  1. start the program (runs to main).
  2. call func1(...) with its output redirected to a file.

This answer shows how to redirect the output wherever you want at an arbitrary point in program execution.

Upvotes: 1

Related Questions