The exec node fails to execute a command that works in the terminal

Hello everyone and thank you for all your answers avaliable on this forum which allowed me to discover node-red and a little programming.
I am a total newbie and my question may seem silly to you: What can prevent an exec node from executing a command that works in the terminal?
Let me explain :
I would like to "mute" and "unmute" the raspberry 3b sound output with an exec node (i use pulseaudio). I tried many command found on various sources but: no succes.
For example, the following two commands work in the terminal but give the following errors when executed in an exec node :

  • pi @ raspberrypi: ~ $ amixer -q -D pulse sset Master toggle
    => ALSA lib pulse.c: 243: (pulse_connect) PulseAudio: Unable to connect: Connection refusedamixer: Mixer attach pulse error: Connection refused

  • pi @ raspberrypi: ~ $ pactl set-sink-mute @ DEFAULT_SINK @ toggle
    => Failed during connection: Connection refused Connection pa_context_connect () failed: Connection refused

I checked my configuration (cat /proc/asound/cards, amixer controls and contents, aplay --list-devices and pcms) but analyse their results is difficult for me.
I checked raspberry and debian forums to found various command to test and i found 3.
I cheked the groups and added the user pi to the pulse and pulse-access groups, but that doesn't change anything.
I checked this forum, with no succes.

Anyone have an idea?

This is likely because pulseaudio requires an Xwindow environment to run. So you can run these on the terminal window of an Xwindow session but similarly not if you connect to a terminal via SSH. The command can likely be made to connect to an existing Xwindow session using an environment variable. I think there was a similar discussion here at some point. I'll see if I can find it.

Here for example Exec script to UI app

Try configuring the exec node to run for example:

export DISPLAY=:0 && amixer -q -D pulse sset Master toggle
2 Likes

Indeed, it works like this. Many thanks.
I should have thought about it because I was already faced with this problem of "Display:0" that I had solved without understanding it. Now I know what it is!
Thanks again,
Laurent

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.