【问题标题】:How to store output of hcitool lescan? [duplicate]如何存储 hcitool lescan 的输出? [复制]
【发布时间】:2016-06-16 13:30:10
【问题描述】:

我试图在 python 代码中使用 hcitool lescan 扫描 ble 设备。 hcitool lescan 在命令行上运行良好,但使用 subprocess.Popen 无法返回任何输出。当将 lescan 替换为“scan”即扫描传统蓝牙时,代码运行良好。 我的代码是:

import os
import time
import subprocess 
proc = subprocess.Popen(['sudo','timeout', '20s','hcitool', 'lescan'],stdout=subprocess.PIPE)
proc.wait()
lines = proc.stdout.readlines()
print lines

【问题讨论】:

  • 你是从哪里想到在.readlines()之前打电话给.wait()的?

标签: python-2.7 bluetooth subprocess bluez


【解决方案1】:

你试过用交流吗?

proc = subprocess.Popen(...)
stdout, stderr = proc.communicate()

【讨论】:

    【解决方案2】:

    使用

    from commands import getoutput as shell
    s = shell('hcitool scan')
    

    s 是您要查找的字符串。

    【讨论】:

      猜你喜欢
      • 2016-06-24
      • 2014-03-30
      • 2017-04-17
      • 2015-01-08
      • 2021-03-26
      • 2016-08-05
      • 2021-08-31
      • 2017-10-21
      • 1970-01-01
      相关资源
      最近更新 更多