seanborland has asked for the wisdom of the Perl Monks concerning the following question:

I want to write a perl program to control gdb. i.e. the command is put into my program and then passed to gdb, and gdb's output is put into my program and then displayed. I use open2 but it can not fulfil my requirement. Can someone be kind enough to give some demo code? Thanks a lot.

Replies are listed 'Best First'.
Re: how to write a program to control gdb
by matija (Priest) on Feb 29, 2004 at 16:35 UTC
    I have two words for you: use Expect. Look at Expect module, and I'm willing to bet you will find it much easier to use than open2.
      thank you very much
Re: how to write a program to control gdb
by hv (Prior) on Mar 09, 2004 at 18:16 UTC

    I'm sure it must be possible using Expect.pm, but last time I tried this (a few years ago) I didn't get very far, and it seemed easiest to use Perl to glue a TCL-style expect script and do the post-processing, as in this script which I used to generate a labelled disassembly of one function of a program.

    I can't remember now what problems I had with Expect.pm - it may be related to the fact that I learnt TCL before perl, and had used expect extensively in that period.

    Hugo