import pexpect
child = pexpect.spawn ('ftp ftp.openbsd.org')
child.expect ('Name .*: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('noah@example.com')
child.expect ('ftp> ')
child.sendline ('ls /pub/OpenBSD/')
child.expect ('ftp> ')
print child.before # Print the result of the ls command.
child.interact() # Give control of the child to the user.
使用pexpect。它是一个python模块,用于与本地或远程进程交互。下面是一个来自其网站的示例,展示了如何使用它连接到键盘驱动的FTP子进程。在
您所需要的只是查找键(如control)的特殊控制代码。在
相关问题 更多 >
编程相关推荐