如何:在 shell 中模拟在嵌入式目标中运行的应用程序的击键输入
我正在编写一个在嵌入式 Linux 目标上运行的自动化脚本。
该脚本的一部分涉及在目标上运行应用程序并从标准输出获取一些数据。这里的标准输出是我与目标的 ssh 终端连接。
但是,仅当按下某些键时,此数据才可在标准输出上使用,并且按键必须在连接到嵌入式目标的键盘上完成,而不是在我通过 ssh 连接到目标的主机系统上完成。有什么办法可以模拟这个吗?
编辑: 详细说明我需要什么 -
我有一个在嵌入式 Linux(像常规 Linux 一样工作)目标上运行的 OpenGL 应用程序。这会在嵌入式系统的显示设备上显示一些图形。按连接到目标的键盘上的 f 会将 fps 数据输出到我控制目标的 ssh 终端。
由于我正在自动化运行此 OpenGL 应用程序并获取 fps 分数的过程,因此我不能期望键盘连接到目标,更不用说期望用户在嵌入式目标键盘上输入击键。我该怎么办?
编辑2: Expect 不起作用,因为 Expect 只能向 ssh 终端发出笔画。我需要发送到应用程序的击键必须来自连接到目标的键盘(这是需要模拟但实际上没有连接键盘的部分)。
谢谢。
I am writing an automation script that runs on an embedded linux target.
A part of the script involves running an app on the target and obtaining some data from the stdout. Stdout here is the ssh terminal connection I have to the target.
However, this data is available on the stdout only if certain keys are pressed and the key press has to be done on the keyboard connected to the embedded target and not on the host system from which I have ssh'd into the target. Is there any way to simulate this?
Edit:
Elaborating on what I need -
I have an OpenGL app that I run on the embedded linux (works like regular linux) target. This displays some graphics on the embedded system's display device. Pressing f on the keyboard connected to the target outputs the fps data onto the ssh terminal from which I control the target.
Since I am automating the process of running this OpenGL app and obtaining the fps scores, I can't expect a keyboard to be connected to the target let alone expect a user to input a keystroke on the embedded target keyboard. How do I go about this?
Edit 2:
Expect doesn't work since expect can issue strokes only to the ssh terminal. The keystroke I need to send to the app has to come from the keyboard connected to the target (this is the part that needs simulation without actually having a keyboard connected to it).
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这完全是 Expect 的域,stackoverflow 顺便用它自己的属性来识别它标签。
实现您所追求的 OpenGL 自动化的最快方法,同时尽可能少地学习 Expect,可能是通过 自动预期。
This is exactly the domain of Expect , which stackoverflow incidentally recognizes with its own tag.
The quickest way to achieve the OpenGL automation you're after, while learning as little of Expect as necessary, is likely by way of autoexpect.
我现在不在家(所以手头没有linux),所以无法实际尝试。但是,如果您将所需的按键(可能是键盘代码)回显到位于目标上 /dev 下的键盘节点,您应该能够模拟击键。这可以通过你的 ssh 来完成。
I'm not at home right now (so no linux at hand), so can't actually try it out. But you should be able to emulate keystrokes if you echo the desired keypresses (possibly the keyboard codes) to the keyboard node located under /dev on your target. This could be done through your ssh.
满足质量保证和制造测试的解决方案是构建一个硬件,它看起来像嵌入式设备的键盘并具有外部控制。根据您需要输入的复杂程度,这可能是从商店购买的带有空格键的键盘到键盘侧的 PS/2 或 USB 微控制器以及控制器上的其他东西(串行、USB、以太网)的任何东西边。
借助 LUFA 库,使用 AT90USB 系列部件制作 USB 键盘非常容易。其中一些甚至有 2 个 USB 端口,可以通过连接到另一个系统的 USB 实现自动化(或者如果您想厚颜无耻,您可以让它同时枚举为键盘和控制设备,并通过嵌入式系统循环键盘输入)。
A solution which would satisfy both QA and manufacturing test is to build a piece of hardware which looks like a keyboard to the embedded device and has external control. Depending on how complex your input needs to be this could be anything from a store-bought keyboard with the spacebar taped down to a microcontroller talking PS/2 or USB on the keyboard side and something else (serial, USB, ethernet) on the control side.
With the LUFA library it is remarkably easy to make a USB keyboard with AT90USB series parts. Some of them even have 2 USB ports and could be automated by USB connected to another system (or if you want to get cheeky you could have it enumerate both as a keyboard and the control device and loop the keyboard input through the embedded system).
echo "f" > 怎么样? /dev/console ?
How about
echo "f" > /dev/console ?
创建包含输入的文本文件并按如下方式运行怎么样?
input.txt 的内容可以如下所示,
How about create text file with inputs and run as follows?
Contents of inputs.txt can be something like follows,