向进程发送命令
使用bash,是否可以将相当于空格键的击键发送到进程?如果是这样,该怎么办?
编辑以澄清我想要实现的目标:假设我正在运行一个 mplayer 进程,并且我想暂停当前歌曲的执行,我将如何实现这一目标?
Using bash, is it possibile to send the equivalent of a space bar stroke to a process? If so, how can that be done?
Edit to clarify a bit what I want to achieve: let's say I've got an mplayer process running and I want to pause the execution of the current song, how would I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将标准 I/O 定向到它。如果您使用 Bash,那么您可能还有其他 GNU 工具。 GNU Coreutils 有一个 echo 命令,可以输出几乎任何内容。例如:
但是,如果您需要一个实际的 TTY(终端)并且您有更复杂的要求,请考虑expect,它几乎可以做人类可以做的任何事情(除了思考)。
You can direct standard I/O to it. If you are using Bash, then you probably have other GNU tools. GNU Coreutils has an
echo
command that can output pretty much anything. For example:However if you need an actual TTY (terminal) and you have more sophisticated requirements, look into expect, which can do nearly anything a human can (except think).
您可以使用 kill 命令向进程发送信号。尝试
man Kill
了解更多信息。You can send a signal to a process using kill command. Try
man kill
for more info.