首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >退出logstash

退出logstash
EN

Stack Overflow用户
提问于 2020-05-09 07:49:46
回答 1查看 64关注 0票数 0

我想在我的python脚本中退出logstash,然后在cmd中单击ctrl-c将其关闭。我试图使用其中的一个函数,但它不起作用。任何人都有一个想法,请告诉我怎么做。

代码语言:javascript
复制
import os
import subprocess
import signal

@main.route('/data')
def data():
        ...
        target_dir = os.path.join("C:\elastic_stack\logstash-7.6.2")

        # small check
        if os.path.isdir(target_dir):
            os.chdir(target_dir)
        else:
            print(" pathname does not refer to an existing directory")

        # current working directory
        print(os.getcwd())

        # start logstash directly os.system will return the return code of the command if it's 0 means OK
        os.system(".\\bin\\logstash -f C:\\Users\\Asus\\Dropbox\\PFE_part2\\New_flask_app\\logstash.conf")

        # if you need the output after you started logstash it will work ONLY in Python3

        process = subprocess.Popen([".\\bin\\logstash", "-f", "C:\\Users\\Asus\\Dropbox\\PFE_part2\\New_flask_app\\logstash.conf"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)


        output = process.stdout
        errors = process.stderrt


        #After logstash finished the work above, it shut down       
        os.kill(process.pid, signal.SIGTERM)  #that doesn't work


        process.sendcontrol('c') #or either this
        process.close()

        return render_template('data.html')
EN

回答 1

Stack Overflow用户

发布于 2020-11-26 19:51:49

在C#中,我使用NuGet包Renci,打开CreateShellStream并发送命令shellStream.Write("\u0003");,然后发送sudo命令并执行任务。\u0003是针对Ctrl + C的。也许你可以试着用Python发送它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61689941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档