码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-09-16 17:55:06      阅读:237      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!