开发者

Is it possible to have python open a terminal and write to it?

For example, if I have this code:

subprocess.call(['gnome-terminal'])

Is it possible to have python output strings to that specific terminal that was just op开发者_如何学Cened? Thanks!


Possibly, but it is easier to have a custom process running in the subordinate terminal. For example, given sserv.py from the example server in the documentation the command:

 gnome-terminal -e "python ./sserv.py"

will happily chat on port 9999 with you. Given a more complex sserv.py it could do anything you want (anything terminalish, that is).


I think that PExpect might do this for you:

Pexpect is basically a pattern matching system. It runs programs and watches output. When output matches a given pattern Pexpect can respond as if a human were typing responses. Pexpect can be used for automation, testing, and screen scraping. Pexpect can be used for automating interactive console applications such as ssh, ftp, passwd, telnet, etc. It can also be used to control web applications via lynx, w3m, or some other text-based web browser. Pexpect is pure Python. Unlike other Expect-like modules for Python Pexpect does not require TCL or Expect nor does it require C extensions to be compiled. It should work on any platform that supports the standard Python pty module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜