使用命名管道基于输出发送输入到节目 [英] Use named pipes to send input to program based on output

查看:109
本文介绍了使用命名管道基于输出发送输入到节目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是什么,我需要做一个普通的例子:

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

例如,我会从程序发送命令BT到GDB启动回溯。然后我将搜索的单词,例如pardrivr,并通过使用常规的前pressions获得与之相关联的行号。那我就输入F [line_number_of_pardriver]到GDB。这个过程将被重复,直到正确的信息最终被萃取。

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.

我想使用bash或蟒蛇命名管道来实现。

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?

推荐答案

我的建议是不要这样做。相反,有两个支持的方法去:

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


  1. 用Python语言编写你的code直接在GDB。 GDB已经扩展在Python现在好几年了。

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

使用gdb的MI(机器接口)的方法。有可用的已解析这个库(如果不知道有一个在Python,但我认为如此)。这比解析GDB的命令行输出,因为又痛采取措施去避免无端破碎更好 - 这是preferred方式的程序与GDB交互

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.

这篇关于使用命名管道基于输出发送输入到节目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆