我有一个通过控制台运行的服务器程序. (具体来说,Bukkit MineCraft服务器)我希望能够控制这个程序并读取输出.没有GUI,所以它不应该太难,对吧?
无论如何,我从来没有在python中控制一个控制台而且完全卡住了.有什么建议?
附:我正在使用Debian Linux,因此应该简化一些事情.
我得到了一个很好的答案,但我还需要一件事.我想有一些方法将程序的FULL输出打印到python控制台(逐行排序很好),我需要一些方法将控制台中的命令转发到程序.
解决方法:
像这样的任务的规范答案是使用Pexpect.
Pexpect is a Python module for spawning child applications and controlling
them automatically. Pexpect can be used for automating interactive applications
such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup
scripts for duplicating software package installations on different servers. It
can be used for automated software testing. Pexpect is in the spirit of Don
Libes’ Expect, but Pexpect is pure Python. Other Expect-like modules for Python
require TCL and Expect or require C extensions to be compiled. Pexpect does not
use C, Expect, or TCL extensions. It should work on any platform that supports
the standard Python pty module. The Pexpect interface focuses on ease of use so
that simple tasks are easy.
标签:python,terminal
来源: https://codeday.me/bug/20190621/1255156.html