LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2009, 03:29 PM   #1
calypso9
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
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 ). 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!
 
Old 04-09-2009, 05:30 PM   #2
aero_z
Member
 
Registered: Dec 2008
Posts: 30

Rep: Reputation: 16
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about running a program from terminal window ganoo Linux - Newbie 7 11-01-2010 12:44 PM
Question about page allocation when program initializing and running? valpa Linux - Kernel 2 08-18-2008 11:26 PM
General question on program running in console Eredeath Linux - Newbie 6 08-06-2008 01:19 PM
Question about running a program as a service darbien Programming 12 10-25-2006 07:19 PM
scripting or programming question - running a program ewto Linux - Newbie 2 09-05-2003 11:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration