-   Linux - Newbie (
-   -   Question about running a program with gdb (

calypso9 04-09-2009 04:29 PM

Question about running a program with gdb
I hope I posted this in the right place....
Anyway, I have a program written in C that I'm trying to run in gdb but I can't figure out how to get my input into the program. The program uses getchar() so I normally run it as:

>echo "input" | ./program

So somehow I need to do the echo "input" part in gdb before I do the run command and have the program run as it should, but I don't know the syntax for doing so or if it's actually even possible (because I'm a newbie :p). It'd be easy to fix it to have main() just take an argument, but I can't modify the program, so it has to be this way. Any advice would be appreciated!

aero_z 04-09-2009 06:30 PM

Instead of writing

echo "input" | ./program
you can do

./program <
where is a text file which contains the input text to pipe into the program.

So in gdb you can type:

run <
and it should work.

All times are GMT -5. The time now is 01:28 PM.