import pexpect,sys child = pexpect.spawn(‘/home/cf/elk/Summoner/Elk/logstash/test/bin/logstash -f /home/cf/elk/Summoner/Elk/logstash/test/conf.d‘, timeout=60) #index = child.expect([‘startup completely‘, pexpect.TIMEOUT]) while True: index = child.readline() sys.stdout.write(index) sys.stdout.flush() if index == ‘Logstash startup completed\r\n‘: break n = child.send(‘hello\nworld‘) output = "" while True: index = child.readline() output += (index) if index == ‘}\r\n‘: break sys.stdout.write(output) sys.stdout.flush() #child.kill(15) #index = child.readline() #print index #child.kill(15) #index = child.readline() #print index child.close(force=True) print ‘closed‘
在logstash的配置文件中,设置从stdin输入,所以pexpect的readline会读到所输入的内容,就好像先回显了一下
但利用file input就没有此问题
时间: 2024-10-09 13:28:05