我正在运行一个在套接字上工作的脚本。它需要sudo才能运行。但是,在脚本内部,我调用了另一个不需要作为sudo运行的脚本。
以下是代码:
import subprocess
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.settimeout(5.0)
host='192.168.1.148'
port=1022
s.bind((host, port))
s.listen(5)
while True:
c, addr = s.accept()
subprocess.call("python bluetooth2.py",shell=True)
print 'got connection from',addr
c.send('Thank you for connecting')
#c.settimeout(5.0)
c.recv(1022)
c.close()bluetooth2.py运行脉冲音频,它是以根用户的身份运行的,但由于某些原因而无法工作。任何帮助都非常感谢!
以下是蓝牙2.py脚本的样子,以供参考(调用脉冲音频的脚本)
import time
import pexpect
from sh import bluetoothctl
import subprocess
mac = "C8:84:47:26:E6:3C"
print ("stuck here")
#bluetoothctl("connect", mac)
def connect():
child = pexpect.spawn('bluetoothctl')
child.sendline('power on')
child.sendline('agent on')
child.sendline('default-agent')
child.sendline('pair C8:84:47:26:E6:3C')
time.sleep(1)
child.sendline('trust C8:84:47:26:E6:3C')
time.sleep(1)
child.sendline('connect C8:84:47:26:E6:3C')
print("connecting...")
time.sleep(5)
subprocess.call("pulseaudio --start",shell=True)
subprocess.call("pacmd set-default-sink
bluez_sink.C8_84_47_26_E6_3C",shell=True)
subprocess.call("aplay /home/pi/bleep_01.wav", shell=True)发布于 2021-07-01 13:17:54
为所有用户运行PulseAudio解决方案
在/etc/systemd/system/pulseaudio.service文件中添加以下行并保存
[Unit]
Description=PulseAudio system server
[Service]
Type=notify
ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal
[Install]
WantedBy=multi-user.target
Enable service
sudo systemctl --system enable pulseaudio.service
sudo systemctl --system start pulseaudio.service
sudo systemctl --system status pulseaudio.service编辑客户端conf /etc/pulse/client.conf并替换ass bellow
default-server = /var/run/pulse/native
autospawn = no将根添加到脉冲组
sudo adduser root pulse-access并重新启动系统。
https://stackoverflow.com/questions/41539971
复制相似问题