pexpect - 由于发送而导致超时(不是发送线)

时间:2017-03-20 08:21:04

标签: python python-3.x shell command-line-interface pexpect

我使用pexpect

定义了一个类似于以下内容的send_command函数(它不是整个代码......它是其中的一部分)
def send_command(prompt,command,newline=True):
   //pexpect prompt - expect is defined here----line 1
   if newline:
       p.sendline(command)
   else : 
       p.send(command)
    //pexpect prompt - expect is defined here --- line 2
   return pexpect_index

以下代码适用于newline = True ..但如果我将其称为

send_command(prompt,command,newline=False)

该函数由于期望从第2行调用而给出超时。

示例:

command = ls $($ -gives命令描述) 预期输出=文件和文件夹列表

函数调用: -

send_command(prompt,'show$',newline=False)

结果:超时

buffer (last 100 chars): b'\r\n List of files and folders  \r\n'
E           before (last 100 chars): b'\r\n  List of files and folders\r\n'
E           after: <class 'pexpect.exceptions.TIMEOUT'>
E           match: None
E           match_index: None
E           exitstatus: None
E           flag_eof: False
E           pid: 53425
E           child_fd: 12
E           closed: False
E           timeout: 30
E           delimiter: <class 'pexpect.exceptions.EOF'>

当我在myshell中运行'ls $'时会发生这种情况: -

myshell#ls$
List of files and folders
myshell#ls

请帮我用newline = False运行命令

0 个答案:

没有答案