【问题标题】:Python: run service after hostapdPython:在 hostapd 之后运行服务
【发布时间】:2017-05-07 06:16:47
【问题描述】:

我已经在一个项目上工作了几个星期,但我遇到了一些我无法弄清楚的事情(可能非常简单)!

import os
os.system("service hostapd start && hostapd /etc/hostapd/hostapd.conf")
os.system("service someservicethatIuse start")

当我启动hostapd 时,脚本会暂停,因为它启用了一个访问点。我尝试使用xfce4-terminal --tab -e "hostapd /etc/hostapd/hostapd.conf" --tab -e "service someservicethatIuser start" 运行它,但它似乎不起作用:-/

(语言:Python 2.6)

【问题讨论】:

  • 如果你所做的只是运行 shell 命令,为什么还要使用 Python?

标签: python linux python-2.6 wireless access-point


【解决方案1】:

启动hostapd时使用-B选项,它应该在后台运行

$~/hostapd -B /etc/hostapd/hostapd.conf

【讨论】:

    【解决方案2】:

    我不了解hostapd,但通常运行service foo start 就足以启动服务并且它不会阻塞。

    无论如何,您可以使用 sh & 操作符并行运行 shell 进程:

    import os
    os.system("service hostapd start && hostapd /etc/hostapd/hostapd.conf &")
    os.system("service someservicethatIuse start")
    

    【讨论】:

    • 当我运行它时,它首先启动服务,然后它启动 hostpad
    • 如果其他服务依赖hostapd 启动,脚本等待hostapd 实际启动成功是一个有用的功能。
    猜你喜欢
    • 1970-01-01
    • 2018-04-18
    • 2015-11-28
    • 1970-01-01
    • 2015-06-11
    • 2019-04-25
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多