您的位置:首頁技術文章
文章詳情頁

python中Pexpect的工作流程實例講解

瀏覽:3日期:2022-06-26 16:28:40

1、工作流程步驟

(1)用spawn來執行一個程序;

(2)用expect方法來等待指定的關鍵字,這個關鍵字是被執行的程序打印到標準輸出上面的;

(3)當發現這個關鍵字以后,使用send/sendline方法發送字符串給這個程序。

2、實例

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_forkdef __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()方法用來執行一個程序,返回程序的操作句柄,后續就可以通過操作句柄來與這個程序進行交互了。

知識點擴展:

Pexpect的基本工作流程,基本可以分為以下三個步驟:

首先用spawn來執行一個程序; 然后用expect方法來等待指定的關鍵字,這個關鍵字是被執行的程序打印到標準輸出上面的; 最后當發現這個關鍵字以后,使用send/sendline方法發送字符串給這個程序。

到此這篇關于python中Pexpect的工作流程實例講解的文章就介紹到這了,更多相關python中Pexpect的工作流程內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
国产综合久久一区二区三区