在python中我试图通过蓝牙连接设备。我也想自动发送蓝牙密码。我尝试了一种使用子进程的方法,但是我收到了错误。
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.
答案 0 :(得分:0)
进行调用还有其他问题,处理这样的进程,但最明显的和导致失败的是你正在运行Windows版本的python(执行显然发生在cmd.exe
)和尝试执行类似U * X的命令(并使用类似语法的sh
)。