2

I'm currently designing a script that will, in the end, control a range of games with the ability to start and stop them all from the main script.

However, one of the games can only gracefully stop by pressing the 'ESC' key. How can I interpret this into a signal or something similar?

*The games are started with gamename.Popen() and then usually stopping is done by sending SIGINT or SIGQUIT.

Ideas?

4

2 回答 2

1

但是,其中一款游戏只能通过按下“ESC”键来优雅地停止。我怎样才能将其解释为信号或类似的东西?

你不能。您试图掩盖子进程中的设计错误,我怀疑该错误会获取自己的输入并且不使用允许您发送Esc. 让我知道这个假设是否不正确。

你试过在这个游戏中使用 SIGTERM 吗?这是更传统的“清理自己并退出”信号,我可以想象有人编写代码来优雅地处理 SIGTERM,同时将 SIGINT 和 SIGQUIT 保留为默认值。

于 2013-07-30T12:08:39.167 回答
0

如果您通过使用 PIPE 发送击键来控制它们,那么发送chr(0x1b)应该可以解决问题。

于 2013-07-30T12:07:38.893 回答