python中Pexpect的工作流程

548次阅读
没有评论

python中Pexpect的工作流程

python Pexpect工作流程步骤

(1)用spawn来执行一个程序;

(2)用expect方法来等待指定的关键字,这个关键字是被执行的程序打印到标准输出上面的;

(3)当发现这个关键字以后,使用send/sendline方法发送字符串给这个程序。

python Pexpect实例

spawn类

class spawn(SpawnBase):
    '''This is the main class interface for Pexpect. Use this class to start
    and control child applications. '''
 
    # This is purely informational now - changing it has no effect
    use_native_pty_fork = use_native_pty_fork
   
def __init__(self, command, args=[], timeout=30, maxread=2000,
                     searchwindowsize=None, logfile=None, cwd=None, env=None,
                     ignore_sighup=False, echo=True, preexec_fn=None,
                     encoding=None, codec_errors='strict', dimensions=None,
                     use_poll=False):

通过spawn()方法用来执行一个程序,返回程序的操作句柄,后续就可以通过操作句柄来与这个程序进行交互了。

以上就是python中Pexpect工作流程的介绍,希望能对大家有所帮助。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-05-04发表,共计807字。
新手QQ群:570568346,欢迎进群讨论 Python51学习