- 論壇徽章:
- 1
|
本帖最后由 ace_fei 于 2012-10-19 14:43 編輯
-
- def send(self, s):
- """This sends a string to the child process. This returns the number of
- bytes written. If a log file was set then the data is also written to
- the log. """
- time.sleep(self.delaybeforesend)
- if self.logfile is not None:
- self.logfile.write (s)
- self.logfile.flush()
- if self.logfile_send is not None:
- self.logfile_send.write (s)
- self.logfile_send.flush()
- c = os.write(self.child_fd, s)
- return c
- def sendline(self, s=''):
- """This is like send(), but it adds a line feed (os.linesep). This
- returns the number of bytes written. """
- n = self.send(s)
- n = n + self.send (os.linesep)
- return n
復(fù)制代碼 昨天用pexpect到遠(yuǎn)程服務(wù)器上執(zhí)行cmd的時候失敗, 查看log發(fā)現(xiàn)是發(fā)送的cmd長度被限制在1024內(nèi), 我一開始想可能是pexpect發(fā)送導(dǎo)致的,
不過看到pexpect包中sendline最終調(diào)用的是os.write來發(fā)送命令的,os.write是沒有字?jǐn)?shù)限制的.
我又檢查了幾遍, 最后發(fā)現(xiàn)是服務(wù)器上的命令行長度做了限制, 只接收1024字符的輸入, 差點錯怪pexpect了. |
|