Use named pipes to send input to program based on output

若如初见. 提交于 2019-12-12 04:14:40

问题


Here's a general example of what I need to do:

For example, I would initiate a back trace by sending the command "bt" to GDB from the program. Then I would search for a word such as "pardrivr" and get the line number associated with it by using regular expressions. Then I would input "f [line_number_of_pardriver]" into GDB. This process would be repeated until the correct information is eventually extracted.

I want to use named pipes in bash or python to accomplish this.

Could someone please provide a simple example of how to do this?


回答1:


My recommendation is not to do this. Instead there are two more supportable ways to go:

  1. Write your code in Python directly in gdb. Gdb has been extensible in Python for several years now.

  2. Use the gdb MI ("Machine Interface") approach. There are libraries available to parse this already (not sure if there is one in Python but I assume so). This is better than parsing gdb's command-line output because some pains are taken to avoid gratuitous breakage -- this is the preferred way for programs to interact with gdb.



来源:https://stackoverflow.com/questions/25001824/use-named-pipes-to-send-input-to-program-based-on-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!