0

I was trying to scan ble devices using hcitool lescan in a python code. The hcitool lescan works well on the command line but fails to return any output using subprocess.Popen.The code works fine when lescan is replaced with 'scan' ie scan of conventional bluetooth. My code is:

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

2 Answers2

0

Have you tried to use communicate?

proc = subprocess.Popen(...)
stdout, stderr = proc.communicate()
Hai Vu
  • 37,849
  • 11
  • 66
  • 93
0

Use

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

s is a string with what you are looking for.

Julien Goupy
  • 165
  • 6