請問大家有用過 Python 的 pexpect 嗎
我之前在 linux 用過,我主要是用來進網路設備下一些日常要用的指令
那時候為了 pexpect 才弄一台 linux(因為 windows 不支援)
剛才發現 pexpect 4.0 開始支援 windows 了
我之前要登入設備的指令如下
child = pexpect.spawn('ssh username@ip')
child.expect('assword:')
child.sendline('password')
因為我目前在家沒有設備可以模擬
所以我在 windows 架一個 ssh server(PowerShell Server)
我本來照抄上面
結果發現 windows 不支援 spawn
找了官方文件
As of version 4.0, Pexpect can be used on Windows and POSIX systems. However, pexpect.spawn and
pexpect.run() are only available on POSIX, where the pty module is present in the standard library. See Pexpect
on Windows for more information.
後來發現
要把
【spawn】改成【pexpect.popen_spawn.PopenSpawn】
但是我改了之後
執行又出現
Traceback (most recent call last):
File "C:/Python27/ssh.py", line 7, in <module>
child = pexpect.popen_spawn.PopenSpawn('ssh andy...@127.0.0.1')
File "C:\Python27\lib\site-packages\pexpect\popen_spawn.py", line 45, in __init__
self.proc = subprocess.Popen(cmd, **kwargs)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] 系統找不到指定的檔案。
請問有人有在 windows 下使用過 pexpect 的經驗嗎??
謝謝
--
這是 Google 網上論壇針對「python.tw」群組發送的訂閱通知郵件。
如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 pythontw+u...@googlegroups.com。
如要在這個群組張貼留言,請傳送電子郵件到 pyth...@googlegroups.com。
請前往以下網址造訪這個群組:https://groups.google.com/group/pythontw。
如需更多選項,請前往:https://groups.google.com/d/optout。