I am facing a problem running amixer shell command (in python) on crontab. If I run the amixer command on my terminal, it runs. Also works if I run the python file manually using
$ python3 myPythonScript.py
Following is the python snippet:
import subprocess
child = subprocess.Popen(["amixer", "-D", "pulse", "sget", "Master", "|", "grep", "\"[.%]\""],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
child = child.stdout.read()
logging.info(child)
Receiving the following output in my log file (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'
OS: Raspbian
Also tried adding the crontab in sudo crontab -e
. Same problem. Why is it breaking only on crontab? Any solutions?