LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about running a program with gdb (http://www.linuxquestions.org/questions/linux-newbie-8/question-about-running-a-program-with-gdb-718026/)

calypso9 04-09-2009 03: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
input
>

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 05:30 PM

Instead of writing
Code:

echo "input" | ./program
you can do
Code:

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

So in gdb you can type:
Code:

run < file.in
and it should work.


All times are GMT -5. The time now is 09:46 AM.