首页 > 编程语言 > 详细

python pexpect 启动、与子进程交互的例子--logstash

时间:2015-09-16 17:55:05      阅读:283      评论:0      收藏:0      [点我收藏+]
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就没有此问题

 

python pexpect 启动、与子进程交互的例子--logstash

原文:http://www.cnblogs.com/kuipertan/p/4813722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!