3

I like the idea of nemiver, but i can't get this basic function of nemiver to work: redirect standard input to program. so as my program needs file input instead of manual input, it usually takes the form:

./program < list.txt

but apparently, nemiver does not recognize this simple redirection. and thinks "<" and "list.txt" as separate arguments. this frustrates me greatly. is there a solution to this? Thank you guys so much!

Feverbeaver
  • 157
  • 2
  • 12

2 Answers2

0

If you just want to do a postmortem analysis (and don't need to single-step), you can load a crash-dump (core) file which can be generated under any kind of pipelining/redirection scenario.

( ulimit -c unlimited && ./yourapp <in.txt >out.txt ) || nemiver --load-core=core ./yourapp

This only launches the debugger if a crash or assert occurs.

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
-1

As a quick-and-dirty solution, you can add something like the following at the beginning of main()...

    {
 // programmatically redirect stdio
    const char * stdin_filename="input.txt", * stdout_filename="output.txt";
    assert( dup2(open(stdin_filename ,O_RDONLY),0) != -1 );
    assert( dup2(open(stdout_filename,O_WRONLY),1) != -1 );
    asm(" int3"); // optional breakpoint -- kills program when not debugging
    }

Just make sure that you disable this when not debugging (since presumably you want to use the normal method of redirection in that case).

You also need the following...

#include <unistd.h>
#include <fcntl.h>
Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173