3

So I am trying to debug a program which requires the user to input some text through the terminal:

$ echo 'here is the text' | ./program

How do I simulate that input in GDB?

imre
  • 369
  • 2
  • 5
  • 17

2 Answers2

6

You can run the program with input redirected:

echo 'here is the text' > intput.txt
gdb ./program
(gdb) run < intput.txt
Employed Russian
  • 182,696
  • 29
  • 267
  • 329
-1

You can do using --args option giving program executable followed by arguments as below,

 % gdb --args ./program arg1 arg2 
Sunil Bojanapally
  • 11,964
  • 4
  • 34
  • 43