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

**URL:** <https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897>\
**Category:** General\
**Created:** [6 June 2020 14:20 UTC](https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897 "2020-06-06T14:20:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Laurent](https://discourse.nodered.org/u/Laurent)\
**Post date:** [6 June 2020 14:20 UTC](https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897/1 "2020-06-06T14:20:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [6 June 2020 14:59 UTC](https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897/2 "2020-06-06T14:59:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [6 June 2020 15:02 UTC](https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897/3 "2020-06-06T15:02:29Z")

</div>

Here for example [Exec script to UI app](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/2)

Try configuring the exec node to run for example:

```auto
export DISPLAY=:0 && amixer -q -D pulse sset Master toggle

```

---

<div class="post-metadata">

**Author:** ![Laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Laurent](https://discourse.nodered.org/u/Laurent)\
**Post date:** [6 June 2020 15:14 UTC](https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897/4 "2020-06-06T15:14:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 June 2020 15:14 UTC](https://discourse.nodered.org/t/the-exec-node-fails-to-execute-a-command-that-works-in-the-terminal/27897/5 "2020-06-20T15:14:49Z")

</div>

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