【发布时间】:2018-02-09 15:47:09
【问题描述】:
在 python 中,我试图通过蓝牙连接设备。我还想自动发送蓝牙密码。我尝试了一种使用 subprocess 的方法,但出现错误。
代码
import subprocess
from bluetooth import *
print "performing inquiry..."
nearby_devices = discover_devices(lookup_names = True)
print "found %d devices" % len(nearby_devices)
for name, addr in nearby_devices:
print " %s - %s" % (addr, name)
# kill any "bluetooth-agent" process that is already running
subprocess.call("kill -9 `pidof bluetooth-agent`",shell=True)
# Start a new "bluetooth-agent" process where XXXX is the passkey
status = subprocess.call("bluetooth-agent 9999 &",shell=True)
# Now, connect in the same way as always with PyBlueZ
# Create the client socket
client_socket=BluetoothSocket( RFCOMM )
client_socket.connect(("08:3D:88:1D:61:41", 3))
错误
'kill' is not recognized as an internal or external command,
operable program or batch file.
'bluetooth-agent' is not recognized as an internal or external command,
operable program or batch file.
【问题讨论】:
标签: python bluetooth subprocess