我正在尝试以sudo的形式执行pexpect spawn命令,并得到超时错误。
import pexpect,os,commands,getpass
child = pexpect.spawn ('su - oracle -c "/home/Middleware/bin/emctl status oms -details"')
child.expect("Enter Enterprise Manager Root (SYSMAN) Password :")
child.sendline("welcome1")
child.expect(pexpect.EOF, timeout=None)
cmd_show_data = child.before
cmd_output = cmd_show_data.split('\r\n')
for data in cmd_output:
print data
以下是执行输出:
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
version: 2.3 ($Revision: 399 $)
command: /bin/su
args: ['/bin/su', '-', 'oracle', '-c', '/home/Middleware/bin/emctl status oms -details']
searcher: searcher_re:
0: re.compile("Enter Enterprise Manager Root (SYSMAN) Password :")
buffer (last 100 chars): , 2016 Oracle Corporation. All rights reserved.
Enter Enterprise Manager Root (SYSMAN) Password :
before (last 100 chars): , 2016 Oracle Corporation. All rights reserved.
Enter Enterprise Manager Root (SYSMAN) Password :
after: