views:

733

answers:

3

I'm trying to debug a program using gdb mode in emacs. It was compiled with g++, and I'm using cygwin. My program takes one command line argument, and also takes input from stdin, which I redirect from a file, like this:

program.exe inputFile.dat <otherInput.dat

The problem is, gdb is sending the string

"<otherInput.dat"

as a command line argument instead of redirecting stdin. How do I force gdb to redirect stdin?

EDIT:

Within gdb, I'm using the command:

run inputFile.dat <otherInput.dat

It doesn't work when I use gdb outside of emacs, either.

EDIT #2:

dfa pointed out a similar question: http://stackoverflow.com/questions/455544/how-to-load-program-reading-stdin-and-taking-parameters-in-gdb

Unfortunately, the accepted answer for that question isn't working for me... Could it be a cygwin-related bug?

+3  A: 

It seems that you have to use the run command:

You can redirect your program's input and/or output using shell redirection with the run > command. For example,

run > outfile

http://sourceware.org/gdb/current/onlinedocs/gdb_5.html#SEC24

Bastien Léonard
that's what I'm doing, but it doesn't redirect.
Colin
This is why: http://www.cygwin.com/ml/cygwin/1998-11/msg00978.html 1988 and still not fixed, I guess
Arkadiy
A: 

If you are using bash, you can attach gdb to the process immediately by doing PROGRAM ARGS < FILE & jobs -x gdb PROGRAM %1. Depending on the shell you use, you may find yourself having to use more creative methods (probably involving output from ps -C being redirected into gdb's command line).

coppro