[ale] OT: Sending Commands to GDB
Brian Pitts
brian at polibyte.com
Wed Jan 19 11:51:26 EST 2011
On 01/19/2011 09:25 AM, Tim Watts wrote:
> More progress. Try this:
>
> #!/bin/bash
> sleep 0.5
> cat
> echo quit
> sleep 0.5
>
> and this:
>
> $ echo pwd |./gdbin|gdb /bin/true
This is interesting Tim, thanks for your help. You too Michael. You put
me on the write track to play around with Python's subprocess module.
The communicate() method
1. (optionally) sends data to stdin
2. reads data from stdout and stderr, until end-of-file is reached.
3. Waits for process to terminate.
g = subprocess.Popen('gdb /bin/true', shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
g.communicate('pwd\n')
Not surprisingly based on our experiences, the pwd command was not
executed. The only output after the missing debuginfo warnings is
(gdb) Hangup detected on fd 0\nerror detected on stdin\n
But what if I write to stdin before calling communicate?
g = subprocess.Popen('gdb /bin/true', shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
g.stdin.write('pwd\n')
g.communicate()
Like your experiments suggested, this works. The last of the output is
(gdb) Working directory /home/brian.\n(gdb) Hangup detected on fd
0\nerror detected on stdin\n
If I throw in a
g.stdin.write('quit\n')
I can avoid the final hangup and error messages.
> [BTW, how is this OT?]
I don't remember why I thought the post would be OT when I started
writing it last night. It didn't end up that way.
--
All the best,
Brian Pitts
More information about the Ale
mailing list