4
votes

I'm running gdb (or cgdb) but during the debug I need to get some data from stdin. So how can I insert some text or numbers as input to the program while I debug it in gdb?

Thanks in advance!

1
Can you attach to already running program? - ks1322
How would you do it if you weren't running gdb? You can probably do something similar, if not the same, with gdb. - Mark Plotnick
For instance if I use 'scanf' and I'm trying to debug the program will expect in certain moment some data from stdin. So when I step over the scanf line and enter something I cannot continue debugging. - user6299344

1 Answers

2
votes

If you were doing it from a shell you'd do it like this:

gdb myprogram
gdb> run params ... < input.txt