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
  • 379
  • 2
  • 6
  • 17
  • Possible duplicate of [How to load program reading stdin and taking parameters in gdb?](http://stackoverflow.com/questions/455544/how-to-load-program-reading-stdin-and-taking-parameters-in-gdb) – Ciro Santilli OurBigBook.com Apr 23 '17 at 08:49

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
  • 199,314
  • 34
  • 295
  • 362
-1

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

 % gdb --args ./program arg1 arg2 
Sunil Bojanapally
  • 12,528
  • 4
  • 33
  • 46