0

我在 crontab 上运行 amixer shell 命令(在 python 中)时遇到问题。如果我在终端上运行 amixer 命令,它就会运行。如果我使用手动运行 python 文件也可以使用

$ python3 myPythonScript.py

以下是python片段:

import subprocess
child = subprocess.Popen(["amixer", "-D", "pulse", "sget", "Master", "|", "grep", "\"[.%]\""],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
child = child.stdout.read()
logging.info(child)

在我的日志文件(子)中接收以下输出:

none
b'ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused\n\namixer: Mixer attach pulse error: Connection refused\n'

操作系统:树莓派

还尝试在sudo crontab -e. 同样的问题。为什么它只在 crontab 上中断?有什么解决办法吗?

4

0 回答 0