# Issue: PulseAudio command working with console but not in Exec node

**URL:** <https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716>\
**Category:** General\
**Created:** [5 June 2021 06:22 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716 "2021-06-05T06:22:08Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 06:22 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/1 "2021-06-05T06:22:09Z")

</div>

Hi All,

I'm having an issue that I'm not able to fix when using a | (pipe) in an exec node. The full command I am trying to exec is:

`pactl load-module module-loopback latency_msec=1 source=2 sink=1 | multimon-ng -a DTMF /dev/stdin`

But the command will not get executed and the error message thrown is:  
`Failure: Module initialization failed`

However if I just exec the below command in the exec node, it works:  
`pactl load-module module-loopback latency_msec=1 source=2 sink=1`

And if I just exec the below command in the exec node, it also works:  
`multimon-ng -a DTMF`

So I tried the above two commands that are failing in node-red, by executing them directly in the console. Both work:

```auto
pi@raspberrypi:~ $ pactl load-module module-loopback latency_msec=1 source=2 sink=1 | multimon-ng -a DTMF /dev/stdin
multimon-ng 1.1.8
  (C) 1996/1997 by Tom Sailer HB9JNX/AE4WA
  (C) 2012-2019 by Elias Oenal
Available demodulators: POCSAG512 POCSAG1200 POCSAG2400 FLEX EAS UFSK1200 CLIPFSK FMSFSK AFSK1200 AFSK2400 AFSK2400_2 AFSK2400_3 HAPN4800 FSK9600 DTMF ZVEI1 ZVEI2 ZVEI3 DZVEI PZVEI EEA EIA CCIR MORSE_CW DUMPCSV X10 SCOPE
Enabled demodulators: DTMF

```

So I suspect the exec-node does not handle the pipe properly.

I hope someone has faced the same issue and can help me.

PS: It is not a matter of appending the msg.payload as I am even trying by passing the entire command manually in the exec node to make sure the command is executed properly.

Thanks all

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 June 2021 06:49 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/2 "2021-06-05T06:49:17Z")

</div>

Welcome to the forum @janedoe123

I am not at my computer so cannot test at the moment. Have you tried a simple command with pipe such as`cat` piping into `grep` to check that it is the pipe that is the problem?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 June 2021 06:56 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/3 "2021-06-05T06:56:12Z")

</div>

It is more likely an environment thing.

How do you launch node-red? From command line terminal? run as a service? PM2?

Also, what account runs node-red?

Try adding this flow - what do you see in debug window?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c2c1fea85cc8eb969597597086e424e133d7f515.png)

printenv...

```auto
[{"id":"67000189.da769","type":"inject","z":"5e6c8b.7f38b374","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1420,"y":880,"wires":[["7e0062b2.c73adc"]]},{"id":"7e0062b2.c73adc","type":"exec","z":"5e6c8b.7f38b374","command":"printenv","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1578,"y":880,"wires":[["bd65cfa7.0626a"],[],[]]},{"id":"bd65cfa7.0626a","type":"function","z":"5e6c8b.7f38b374","name":"","func":"var lines = msg.payload.split(\"\\n\")\nvar envvars = {};\nfor(let i = 0; i < lines.length; i++) {\n let line = lines[i];\n let parts = line.split(\"=\");\n envvars[parts[0]]=parts[1];\n}\nmsg.payload = envvars;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1754,"y":880,"wires":[["36b59d59.44c5a2"]]},{"id":"36b59d59.44c5a2","type":"debug","z":"5e6c8b.7f38b374","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1924,"y":880,"wires":[]}]

```

then from a terminal where your command works, enter `printenv` - how do the env vars differ?

lastly,

stop node-red service (assumption) and from the terminal where your command works, enter `node-red` to start up node-red. run the above flow once more - do the correct env vars appear this time?

If so, then you can modify the service to include extra env vars required.

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 07:06 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/4 "2021-06-05T07:06:15Z")

</div>

Thank you Steve !

Node-RED is automatically launched on boot.

Standard user runs Node-RED (in my case, it is "pi" account as I am use a Raspberry Pi), I have checked in the service file.

Running your flow gives the below result:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/5230a85015c9188937448825809c0d5449dc2611.png)

And executing printenv in the console where the command works gives:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad18397bd5ac74842ef2c12ee677839ea636c8f4.png)

The only difference I can see is SHLVL=1 in the console, and SHLVL=0 in node-RED.

The environment vars seem to be ok... Is there something I am missing out?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 June 2021 07:16 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/5 "2021-06-05T07:16:25Z")

</div>

> [@janedoe123](#):
>
> SHLVL=1 in the console, and SHLVL=0 in node-RED.

I dont think the Shell Level will matter.

> [@janedoe123](#):
>
> The environment vars seem to be ok... Is there something I am missing out

Hmm, there are also a few env vars missing (NO\_AT\_BRIDGE, XDG\_SESSION, DISPLAY, LC\_ALL, DBUS\_SESSION) and slight difference in path (that shouldnt matter tho) - one of these might be important to the execution?

Did you try Colins simple pipe test to rule that out?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 June 2021 07:25 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/6 "2021-06-05T07:25:35Z")

</div>

A simple `ps -ef | grep node` works fine so no not an issue with exec node and pipe.

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 07:26 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/7 "2021-06-05T07:26:33Z")

</div>

Thanks Steve,

Indeed there are few env vars missing: NO\_AT\_BRIDGE, XDG\_SESSION, DISPLAY, LC\_ALL, DBUS\_SESSION

The cat | grep command works as suggested by Colin:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/ef85e41e5b4c0790ffcad6e6676979610e333d9a.png)

So the question is: How to add the missing env vars to make sure they are taken into account by Node-RED?

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 07:27 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/8 "2021-06-05T07:27:56Z")

</div>

> [@janedoe123](#):
>
> NO\_AT\_BRIDGE, XDG\_SESSION, DISPLAY, LC\_ALL, DBUS\_SESSION

Indeed. Do you know how to add the missing end vars NO\_AT\_BRIDGE, XDG\_SESSION, DISPLAY, LC\_ALL, DBUS\_SESSION in order to make sure my command is executed?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 June 2021 07:35 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/9 "2021-06-05T07:35:39Z")

</div>

> [@janedoe123](#):
>
> in order to make sure my command is executed

Just a heads up - this is only a suggestion & may not be the cause/fix (i.e. lets rule out env vars before digging)

As a quick and dirty test, you could set the env vars before the command in the exec node e.g. `export DISPLAY=:0 _MY_COMMAND_XXXX YYYY ZZZZ`

e.g. if you change my demo flow to exec `DISPLAY=:0 printenv` you will see DISPLAY is now one of the env vars.

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 07:37 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/10 "2021-06-05T07:37:23Z")

</div>

I just ran into this post from knolleary

[Nov '19](https://discourse.nodered.org/t/how-to-set-env-variable/18612/5)

One way of setting environment variables is in your `settings.js` file.

The following will set the env var `MY_ENV_VAR` :

```auto
process.env.MY_ENV_VAR = "Hello World";

```

You can add lines like that to the top of your settings file.

* * *

Does it mean I need to force them all in settings.js ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 June 2021 07:40 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/11 "2021-06-05T07:40:27Z")

</div>

I dont think that setting env vars in settings.js will cause exec to inherit them - I am pretty sure thats for function nodes / change nodes to access additional variables about its "env".

I might be wrong though - you could always try modifying settings.js, re-run the flow i posted - does printenv show your new variables?

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 08:13 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/12 "2021-06-05T08:13:58Z")

</div>

> [@Steve-Mcl](#):
>
> NO\_AT\_BRIDGE, XDG\_SESSION, DISPLAY, LC\_ALL, DBUS\_SESSION

Here is what I just tried in the exec node. The command is successfully executed:  
`multimon-ng -a DTMF`

However if I force the below env var in the exec node, with exactly the same command, it fails with the node returning **rc:-2** :  
`NO_AT_BRIDGE=1 XDG_SESSION_TYPE=tty DISPLAY=:0 LC_ALL=en_US.UTF-8 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus multimon-ng -a DTMF`

I've tried the env var one by one, same result:  
`NO_AT_BRIDGE=1 multimon-ng -a DTMF`  
`XDG_SESSION_TYPE=tty multimon-ng -a DTMF`  
`DISPLAY=:0 multimon-ng -a DTMF`  
`LC_ALL=en_US.UTF-8 multimon-ng -a DTMF`  
`DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus multimon-ng -a DTMF`

Am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 10:30 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/13 "2021-06-05T10:30:55Z")

</div>

Ok so I have tried something else.

In the console, I am executing the below comand:

`pi@raspberrypi:~ $ pactl load-module module-loopback latency_msec=1 source=1 sink=0 | multimon-ng -a DTMF /dev/stdin`

It is successfully working:

```auto
multimon-ng 1.1.8
  (C) 1996/1997 by Tom Sailer HB9JNX/AE4WA
  (C) 2012-2019 by Elias Oenal
Available demodulators: POCSAG512 POCSAG1200 POCSAG2400 FLEX EAS UFSK1200 CLIPFSK FMSFSK AFSK1200 AFSK2400 AFSK2400_2 AFSK2400_3 HAPN4800 FSK9600 DTMF ZVEI1 ZVEI2 ZVEI3 DZVEI PZVEI EEA EIA CCIR MORSE_CW DUMPCSV X10 SCOPE
Enabled demodulators: DTMF

```

If I try to launch the very same command using Node-RED and having a look at the logs, I am getting the below error message:

```auto
Failed to parse module arguments
Failed to load module "module-loopback" (argument: "latency_msec=1 source=1 sink=0 | multimon-ng -a DTMF /dev/stdin"): initialization failed.
^C

```

I also found a similar thread here: [Exec Node and Terminal Problem ( Alsa)](https://discourse.nodered.org/t/exec-node-and-terminal-problem-alsa/24980)  
Not sure it is related to the same issue...

I am really clueless... Why would it work with the console, and not node-Red ?

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [5 June 2021 11:25 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/14 "2021-06-05T11:25:30Z")

</div>

Ok folks,

I think I got it work but I don't know why... Is this a bug in node-red ?

I took the command `pactl load-module module-loopback latency_msec=1 source=1 sink=0 | multimon-ng -a DTMF /dev/stdin` and created a pulse.sh script as follows:

```auto
#!/bin/sh

pactl load-module module-loopback latency_msec=1 source=1 sink=0 | multimon-ng -a DTMF /dev/stdin

```

In the node-red exec node, I am calling the pulse.sh as follows:  
`/home/pi/Documents/pulse.sh`

Guess what ? It works!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/783eb859b43c72387a1d5a46f8f1ba0936dbc572.png)

I really don't know why... That's worrying actually... Does anyone have any idea?

---

<div class="post-metadata">

**Author:** ![janedoe123](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@janedoe123](https://discourse.nodered.org/u/janedoe123)\
**Post date:** [6 June 2021 04:42 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/15 "2021-06-06T04:42:28Z")

</div>

Small up 🙂 Is this a Node-Red bug?

PS: I haven't even added/modified any env var for that to work.

---

<div class="post-metadata">

**Author:** ![9886815d5d5c584c03d8](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9886815d5d5c584c03d8/32/5088_2.png) [@9886815d5d5c584c03d8](https://discourse.nodered.org/u/9886815d5d5c584c03d8)\
**Post date:** [21 July 2021 23:29 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/16 "2021-07-21T23:29:42Z")

</div>

I was having trouble with pulseaudio commands from the exec node and found that it was an environment issue.

To solve it i used... XDG\_RUNTIME\_DIR=/run/user/1000 pactl info

This worked on a headless Raspberry Pi and my desktop machine.

---

<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:** [19 September 2021 23:30 UTC](https://discourse.nodered.org/t/issue-pulseaudio-command-working-with-console-but-not-in-exec-node/46716/17 "2021-09-19T23:30:36Z")

</div>

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