0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

The program doesn't have the full libc included; it's written in asm and has minimal syscalls. So I'm not sure if the method in the linked answer will work. Is it possible to issue the equivalent of start > logfile or some other way of using r > redirect without actually doing a full r?
Also: Can you explain why you can't run some code in a program "without first running the program."? Imagine the code I wish to call was the entrypoint.
@SRobertJames Revealing your restrictions and preconditions after an answer is provided wastes everyone's time. Can you edit the question to at least explain why a simple (gdb) starti > /tmp/output (gdb) call func1(...) doesn't work for you?
Thank you, that solves it. For some reason, start can't be redirected, but starti (which I was not familiar with) can be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.