- 论坛徽章:
- 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
复制代码 昨天用pexpect到远程服务器上执行cmd的时候失败, 查看log发现是发送的cmd长度被限制在1024内, 我一开始想可能是pexpect发送导致的,
不过看到pexpect包中sendline最终调用的是os.write来发送命令的,os.write是没有字数限制的.
我又检查了几遍, 最后发现是服务器上的命令行长度做了限制, 只接收1024字符的输入, 差点错怪pexpect了. |
|