在后台用python运行bash命令而不杀死我

2024-04-19 19:51:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用python执行bash命令。问题是该程序需要在后台运行,所以我尝试用“amp;amp;”执行代码,但子进程模块会终止它。在

我能帮谁?在

def run_command(bashCommand):
    process = subprocess.Popen(bashCommand, shell=True)
    output, error = process.communicate()
    return output

command = 'bettercap -iface wlx485d60575bf2 -eval "set api.rest.username bettercap; set api.rest.password bettercap; set api.rest.address 127.0.0.1; set api.rest.port 8011; net.probe on; api.rest on" &'
run_command(command)

[解决]它只会在你试图得到输出时杀死它。在

^{pr2}$

Tags: run命令程序bashrestapioutputon