3
使用python pty模块,我想发送一些命令到终端模拟器,使用函数作为标准输入(如pty模块想要的),然后强制退出。我想过像发送命令并退出使用python pty伪终端进程
import pty
cmnds = ['exit\n', 'ls -al\n']
# Command to send. I try exiting as last command, but it doesn't works.
def r(fd):
if cmnds:
cmnds.pop()
# It seems is not executing sent commands ('ls -al\n')
else:
# Can i quit here? Can i return EOF?
pass
pty.spawn('/bin/sh', r)
谢谢
你可能想要研究pexpect,它是专为这种事情而设计的:http://www.noah.org/wiki/pexpect – 2012-01-03 11:40:23
我只有pty可用 – Emilio 2012-01-03 13:33:05
我只是试过,不能使它工作,但从文档我得到的功能是与输出交互不接收参数列表 – 2012-01-04 03:58:35