Expect 作为程序包装器
我正在编写一个与 GDB 交互的脚本,并且需要 GDB 认为它已连接到终端。我在网上找到了一些可用于执行此操作的 C 函数参考,但我的程序是用 Groovy (Java) 编写的,我想避免使用 JNI 接口。我认为更好的方法是使用expect。
作为脚本:
#!/usr/bin/env expect
eval spawn $argv
interact
当从我的脚本运行时:
"expect -c 'eval spawn " + cmd + "; interact'".execute()
这些脚本的问题是 Expect 似乎永远不会终止。我希望我的期望包装是通用的,所以我不想陷入特定的单词。我也不想使用 GDB/MI 接口,因为我想生成 GDB 会话的日志,看起来就像您从终端看到的一样。如何让我的期望包装器正确终止?我是否需要担心提供的命令中的引号,或者是否足够智能地找出列表中带有空格的项目仍然是一个参数?
I'm writing a script to interact with GDB and need for GDB to think that it's connected to a terminal. I found some references online to C functions that can be used to do this but my program is written in Groovy (Java) and I want to avoid using the JNI interface. I thought a better way to do this would be to use expect.
As a script:
#!/usr/bin/env expect
eval spawn $argv
interact
When run from my script:
"expect -c 'eval spawn " + cmd + "; interact'".execute()
The problem with these scripts is that expect never seems to terminate. I would like for my expect wrapper to be generic so I don't want to trap on specific words. I also do not want to use the GDB/MI interface because I would like to generate a log of the GDB session that looks like you would see it from a terminal. How can I get my expect wrapper to terminate properly? Do I need to worry about quotes in the provided command or is spawn smart enough to figure out that an item in the list with spaces is still one argument?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您写道您不想使用 JNI。您是否考虑过使用JNA?到目前为止我从未使用过它,但描述看起来很有希望。
You write that you don't want to use JNI. Did you consider using JNA? I never used it so far, but the description looks promising.
这有点混乱,但也许你可以在
script
中运行gdb
。It's a bit of a kludge but maybe you can run
gdb
insidescript
.放弃,只使用 MI 界面
Giving up and just using the MI interface